表中数据如下,ag y countid
23 3 701
23 4 646
23 5 734
30 3 3355
30 4 3325
30 5 2980
我想要的查询结果是这样的 Y 23 30
3 701 3355
4 646 3325
5 734 2980请问如何写这个语句啊
23 3 701
23 4 646
23 5 734
30 3 3355
30 4 3325
30 5 2980
我想要的查询结果是这样的 Y 23 30
3 701 3355
4 646 3325
5 734 2980请问如何写这个语句啊
sum(iif(ag=30,countid,0)) as a30
from ttq group by y
试试吧,感觉挺复杂的,不能无限个ag
我的原表是这样的, id date age
1 2008-4-3 22
1 2008-5-1 33
1 2008-6-1 50而我想要的结果是这样的
23岁以下, 23-29岁 30-35岁 36-45 。
2008年4月 count次数
2008年5月
2008年6月
我通过这个语句select * from (select 23 as ag, month(date) as y,count(id) from fdc.cc where age <=23 group by month(date)
union all
select 30 as ag, month(date) as y,count(id) from fdc.cc where age >=23 and age<=30 group by month(date)) as t我这样写的也就只能返回表中数据如下,
ag y countid
23 3 701
23 4 646
23 5 734
30 3 3355
30 4 3325
30 5 2980
就是不知道前面的select 怎么写