以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 求一个sql语句 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=96652) |
-- 作者:y2287958 -- 发布时间:2017/2/25 11:07:00 -- S elect iif(年龄<=20,\'0-20岁\',iif(年龄<=50 and 年龄>20,\'21-50岁\',iif(年龄>50,\'50岁以上\',null))) As [年龄段],sum(1) As [个数] From {表A} Where 年龄 Is Not null Group By iif(年龄<=20,\'0-20岁\',iif(年龄<=50 and 年龄>20,\'21-50岁\',iif(年龄>50,\'50岁以上\',null))) |
-- 作者:有点蓝 -- 发布时间:2017/2/25 12:06:00 -- 测试没有问题,如果是Sqlserver,iif改为使用Case When
http://www.foxtable.com/webhelp/scr/1827.htm
|