How To Do Percent/Total in SQL?

MySQL: SELECT ROUND( 100.0 * ( SUM(IF(cust_id = 541, 1, 0)) / COUNT(order_id) ), 1) AS percent_total FROM orders; Edit I guess it helps if I would have noticed the postgres tag. I thought it was a MySQL question. PostgreSQL: SELECT ROUND( 100.0 * ( SUM(CASE WHEN cust_id = 541 THEN 1 ELSE 0 END)::numeric … Read more

Slick 3.0 bulk insert or update (upsert)

There are several ways that you can make this code faster (each one should be faster than the preceding ones, but it gets progressively less idiomatic-slick): Run insertOrUpdateAll instead of insertOrUpdate if on slick-pg 0.16.1+ await(run(TableQuery[FooTable].insertOrUpdateAll rows)).sum Run your DBIO events all at once, rather than waiting for each one to commit before you run … Read more

Oracle table column name with space

It is possible, but it is not advisable. You need to enclose the column name in double quotes. create table my_table (“MY COLUMN” number); But note the warning in the documentation: Note: Oracle does not recommend using quoted identifiers for database object names. These quoted identifiers are accepted by SQL*Plus, but they may not be … Read more

SQL Query for 7 Day Rolling Average in SQL Server

Try: select x.*, avg(dailyusage) over(partition by productid order by productid, date rows between 6 preceding and current row) as rolling_avg from (select productid, date, sum(usagecount) as dailyusage from tbl group by productid, date) x Fiddle: http://sqlfiddle.com/#!6/f674a7/4/0 Replace “avg(dailusage) over….” with sum (rather than avg) if what you really want is the sum for the past … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)