COUNT表上的SUM发出“组函数无效”

时间:2016-11-04 03:26:20

标签: mysql count sum

不带SUM的查询

select date_format(b.date,'%d-%b-%Y') as tanggal, b.nomor, b.no_polisi, a.ukuran, a.type , 
if(concat(a.ukuran,' ',a.type) = 'SqPile 40x40 10 M 4ea1/2" Bottom', count(a.type), 0) as 'SqPile 40x40 10 M 4ea1/2" Bottom',
if(concat(a.ukuran,' ',a.type) = 'SqPile 40x40 10 M 4ea1/2" Middle', count(a.type), 0) as 'SqPile 40x40 10 M 4ea1/2" Middle',
if(concat(a.ukuran,' ',a.type) = 'SqPile 40x40 10 M 4ea1/2" Top', count(a.type), 0) as 'SqPile 40x40 10 M 4ea1/2" Top',
if(concat(a.ukuran,' ',a.type) = 'SqPile 40x40 8 M 5ea1/2" Bottom', count(a.type), 0) as 'SqPile 40x40 8 M 5ea1/2" Bottom',
if(concat(a.ukuran,' ',a.type) = 'SqPile 40x40 8 M 5ea1/2" Middle', count(a.type), 0) as 'SqPile 40x40 8 M 5ea1/2" Middle',
if(concat(a.ukuran,' ',a.type) = 'SqPile 40x40 8 M 5ea1/2" Top', count(a.type), 0) as 'SqPile 40x40 8 M 5ea1/2" Top',
if(concat(a.ukuran,' ',a.type) = 'SqPile 45x45 10 M 5ea1/2" Bottom', count(a.type), 0) as 'SqPile 45x45 10 M 5ea1/2" Bottom',
if(concat(a.ukuran,' ',a.type) = 'SqPile 45x45 10 M 5ea1/2" Middle', count(a.type), 0) as 'SqPile 45x45 10 M 5ea1/2" Middle',|
if(concat(a.ukuran,' ',a.type) = 'SqPile 45x45 10 M 5ea1/2" Top', count(a.type), 0) as 'SqPile 45x45 10 M 5ea1/2" Top'|
from nota_pengiriman_detail a
inner join nota_pengiriman_master b on b.id = a.id_master
where b.proyek = 'kssk' group by b.no_polisi, a.type

这里是结果的图像 link of image

但是当我使用SUM函数时,总是返回“组函数无效”

使用SUM查询

select date_format(b.date,'%d-%b-%Y') as tanggal, b.nomor, b.no_polisi, a.ukuran, a.type ,
SUM(if(concat(a.ukuran,' ',a.type) = 'SqPile 40x40 10 M 4ea1/2" Bottom', count(a.type), 0)) as 'SqPile 40x40 10 M 4ea1/2" Bottom',
SUM(if(concat(a.ukuran,' ',a.type) = 'SqPile 40x40 10 M 4ea1/2" Middle', count(a.type), 0)) as 'SqPile 40x40 10 M 4ea1/2" Middle',
SUM(if(concat(a.ukuran,' ',a.type) = 'SqPile 40x40 10 M 4ea1/2" Top', count(a.type), 0)) as 'SqPile 40x40 10 M 4ea1/2" Top',
SUM(if(concat(a.ukuran,' ',a.type) = 'SqPile 40x40 8 M 5ea1/2" Bottom', count(a.type), 0)) as 'SqPile 40x40 8 M 5ea1/2" Bottom',
SUM(if(concat(a.ukuran,' ',a.type) = 'SqPile 40x40 8 M 5ea1/2" Middle', count(a.type), 0)) as 'SqPile 40x40 8 M 5ea1/2" Middle',
SUM(if(concat(a.ukuran,' ',a.type) = 'SqPile 40x40 8 M 5ea1/2" Top', count(a.type), 0)) as 'SqPile 40x40 8 M 5ea1/2" Top',
SUM(if(concat(a.ukuran,' ',a.type) = 'SqPile 45x45 10 M 5ea1/2" Bottom', count(a.type), 0)) as 'SqPile 45x45 10 M 5ea1/2" Bottom',
SUM(if(concat(a.ukuran,' ',a.type) = 'SqPile 45x45 10 M 5ea1/2" Middle', count(a.type), 0)) as 'SqPile 45x45 10 M 5ea1/2" Middle',
SUM(if(concat(a.ukuran,' ',a.type) = 'SqPile 45x45 10 M 5ea1/2" Top', count(a.type), 0)) as 'SqPile 45x45 10 M 5ea1/2" Top'
from nota_pengiriman_detail a
inner join nota_pengiriman_master b on b.id = a.id_master
where b.proyek = 'kssk' group by b.no_polisi

这里的图像应该像这个link of image

任何想法?哪些部分我错过了? 谢谢

0 个答案:

没有答案