高手请进:求SQL语句!!!

flyfishcn 2005-01-12 04:40:58
如何对同一个表的两个字段同时分组??
希望结果集是:table.a,count(table.b),count(table.c)三个字段,请问SQL语句怎么写??
请高手帮忙!!!
...全文
203 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
flyfishcn 2005-01-12
  • 打赏
  • 举报
回复
matrix1996(铁血)
的方法不错,挺简洁!!!
cnzw002 2005-01-12
  • 打赏
  • 举报
回复
菜人年年有,今年特别多
怎么那么多和我一样的
matrix1996 2005-01-12
  • 打赏
  • 举报
回复
Select aaa.a,Count(aaa.b),Sum(aaa.c)
From (Select a,b,Case When c is null then 0 else 1 end c From Table) aaa
Group by aaa.a
matrix1996 2005-01-12
  • 打赏
  • 举报
回复
Select aaa.a,Count(aaa.b),Sum(aaa.c)
From (Select a,b,Case When c is null then 0 else 1 end From Table) aaa
group by aaa.a
flyfishcn 2005-01-12
  • 打赏
  • 举报
回复
只有fly_cat_(1) 方法管用!!
fly_cat_ 2005-01-12
  • 打赏
  • 举报
回复
select a.hdpc,a.zcs,count(b.hdbz) as zcyhds from
(select zchdpc as hdpc,count(zcbh) as zcs from zchdjd group by zchdpc) a
left join zchdjd b
on b.zchdpc =a.hdpc and b.hdbz <> '' group by a.hdpc,a.zcs
flyfishcn 2005-01-12
  • 打赏
  • 举报
回复
zzlazio(sritsb):
SELECT a,count(b),count(c) FROM table GROUP BY a
HAING c is not null

服务器: 消息 8121,级别 16,状态 1,行 11
列 'table.c' 在 HAVING 子句中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。

zzlazio 2005-01-12
  • 打赏
  • 举报
回复
SELECT a,count(b),count(c) FROM table GROUP BY a
HAING c is not null
flyfishcn 2005-01-12
  • 打赏
  • 举报
回复
wenchanyee(叶文强) :

select table1.a,table1.b,table2.c from
(selec a ,count(b) from table group by a ) as table1
(selec a, count(c) from table group by a where not c is null) as table2
where table1.a = table2.a

结果为:
   001 2 2
002 3 2

003就没有了。。。
ctihy_yy 2005-01-12
  • 打赏
  • 举报
回复
不好意思,写错了
select a,count(b) as c1,count(c) as c2
from table
where c <>''
ctihy_yy 2005-01-12
  • 打赏
  • 举报
回复
select a,count(b) as c1,count(c) as c2
from table
where c =''
wenchanyee 2005-01-12
  • 打赏
  • 举报
回复
SELECT a,count(b),count(c) FROM tata GROUP BY a

正确 是这个
刚试了。。。。
郁闷
wenchanyee 2005-01-12
  • 打赏
  • 举报
回复
SELECT table.a,count(table.b),count(table.c) FROM table GROUP BY table.a HAING table.c is not null

的结果是
001 2 2
002 2 2
003 0 0
wenchanyee 2005-01-12
  • 打赏
  • 举报
回复
select table1.a,table1.b,table2.c from
(selec a ,count(b) from table group by a ) as table1
(selec a, count(c) from table group by a where not c is null) as table2
where table1.a = table2.a
vision2000 2005-01-12
  • 打赏
  • 举报
回复
SELECT table.a,count(table.b),count(table.c) FROM table GROUP BY table.a HAING table.c is not null
flyfishcn 2005-01-12
  • 打赏
  • 举报
回复
补充:
希望结果集是:
001 2 2
002 3 2
003 1 0  

请给出完整SQL语句!!!!!!
flyfishcn 2005-01-12
  • 打赏
  • 举报
回复
如何对同一个表的两个字段同时分组??
table如:
a b c
001 1001 t
001 1002 f
002 1003
002 1004 t
002 1005 t
003 1006  

希望结果集是:table.a,count(table.b),count(table.c<>'')三个字段,
请问SQL语句怎么写??

这次问题说清楚了吧?请高手帮忙!!!
wenchanyee 2005-01-12
  • 打赏
  • 举报
回复
统计出c中不为空的记录数 select count(c) from table where not c is null
lingco 2005-01-12
  • 打赏
  • 举报
回复
count (case when c is not null then c else end)
lingco 2005-01-12
  • 打赏
  • 举报
回复
哦,以为是不同表
加载更多回复(5)

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧