COUNT

xxczyc 2012-12-26 09:25:04
select a.thename,a.selfcode,a.parentcode,count(b.selfcode) as cnt from glasstype a,glasstype b 
where a.parentcode='-1' and a.selfcode=b.parentcode
group by a.thename,a.selfcode,a.parentcode,a.theindex
order by a.theindex,a.selfcode

上面的sql语句,只读出了两个两个条件的数据,
我想得到的结果是
thename     selfcode    parentcode       cnt
1          2         3         4
a          b         c         3
c          c         d         0
a          b         a         0
即:a.selfcode=b.parentcode这个条件不满足是,cnt 能否输出0
...全文
51 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxczyc 2012-12-26
  • 打赏
  • 举报
回复
引用 1 楼 wwwwb 的回复:
select a.thename,a.selfcode,a.parentcode,count(b.selfcode) as cnt from glasstype a left join glasstype b on (a.parentcode='-1' and a.selfcode=b.parentcode) group by a.thename,a.selfcod……
万分感谢楼主,刚接触这种类型的。谢谢
wwwwb 2012-12-26
  • 打赏
  • 举报
回复
select a.thename,a.selfcode,a.parentcode,count(b.selfcode) as cnt from glasstype a left join glasstype b on (a.parentcode='-1' and a.selfcode=b.parentcode) group by a.thename,a.selfcode,a.parentcode,a.theindex order by a.theindex,a.selfcode

7,714

社区成员

发帖
与我相关
我的任务
社区描述
Microsoft Office Access是由微软发布的关系数据库管理系统。它结合了 MicrosoftJet Database Engine 和 图形用户界面两项特点。
社区管理员
  • Access
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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