SELECT reason_id,reason_name,reason_jan,reason_feb,reason_mar,reason_apr,reason_may,reason_jun,reason_jul,reason_aug,reason_sep,reason_oct,reason_nov,reason_dec,
SUM(reason_jan+reason_feb+reason_mar+reason_apr+reason_may+reason_jun+reason_jul+reason_aug+reason_sep+reason_oct+reason_nov+reason_dec) as 'total'
FROM REASON GROUP BY ROLLUP ((reason_id,reason_name,reason_jan,reason_feb,reason_mar,reason_apr,reason_may,reason_jun,reason_jul,reason_aug,reason_sep,reason_oct,reason_nov,reason_dec));
Tag : .NET, MySQL, Ms SQL Server 2012, Web (ASP.NET)
SELECT reason_id,reason_name,reason_jan,reason_feb,reason_mar,reason_apr,reason_may,reason_jun,reason_jul,reason_aug,reason_sep,reason_oct,reason_nov,reason_dec,
SUM(reason_jan+reason_feb+reason_mar+reason_apr+reason_may+reason_jun+reason_jul+reason_aug+reason_sep+reason_oct+reason_nov+reason_dec) as _total,total * 100 /_total As _sum
FROM REASON GROUP BY ROLLUP ((reason_id,reason_name,reason_jan,reason_feb,reason_mar,reason_apr,reason_may,reason_jun,reason_jul,reason_aug,reason_sep,reason_oct,reason_nov,reason_dec));
total ในตารางมันมีอยู่แล้ว ถ้า As total มันจะ งงๆนะครับ
SELECT reason_id,reason_name,reason_jan,reason_feb,reason_mar,reason_apr,reason_may,reason_jun,reason_jul,reason_aug,reason_sep,reason_oct,reason_nov,reason_dec,
SUM(reason_jan+reason_feb+reason_mar+reason_apr+reason_may+reason_jun+reason_jul+reason_aug+reason_sep+reason_oct+reason_nov+reason_dec) as _total,total * 100 /_total As _sum
FROM REASON GROUP BY ROLLUP ((reason_id,reason_name,reason_jan,reason_feb,reason_mar,reason_apr,reason_may,reason_jun,reason_jul,reason_aug,reason_sep,reason_oct,reason_nov,reason_dec));
select x.*, x.total * y. total
from ( select *, (f1+f2+f3) as total from tbname group by (...)) as x
, (select sum((f1+f2+f3)) as total from tbname) as y
SELECT x.*,x.total * y.total
from (select *, (reason_jan+reason_feb+reason_mar+reason_apr+reason_may+reason_jun+reason_jul+reason_aug+reason_sep+reason_oct+reason_nov+reason_dec) as total from REASON group by (reason_jan,reason_feb,reason_mar,reason_apr,reason_may,reason_jun,reason_jul,reason_aug,reason_sep,reason_oct,reason_nov,reason_dec) as x
, (select sum((reason_jan+reason_feb+reason_mar+reason_apr+reason_may+reason_jun+reason_jul+reason_aug+reason_sep+reason_oct+reason_nov+reason_dec)) as total from REASON ) as y
ทำไมมันถึงเกิด Error ' , ' ที่เกิดคำสั่ง GROUP BY อะครับ เหมือน syntax มันผิด หรือว่าผมเขียนตรงไหนผิดพลาดครับ