SQL-sql 查询的函数有多个

需求定制 需求定制 主题:1050 回复:2283

SQL-sql 查询的函数有多个

夜无邪 发布于 2017-06-26 字数 628 浏览 1031 回复 1

SELECT p_id,COUNT(*) AS comnum FROM dbo.qbxx where p_id in (select P_id from dbo.people where bm_id='320000' and mj_id='8') GROUP BY p_id 查询出来的结果是
1525013200008001 16
1525013200008002 2
1525013200008003 1

但是现在 select P_id from dbo.people where bm_id='320000' and mj_id='8' 查询出来的结果是
1525013200008001
1525013200008002
1525013200008003
1525013200008004
1525013200008005

我该怎么写 才能得到这种效果

1525013200008001 16
1525013200008002 2
1525013200008003 1
1525013200008004 0
1525013200008005 0

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

支持 Markdown 语法,需要帮助?

评论(1

偏爱自由 2017-08-09 1 楼

select p.p_id,count(q.p_id) as comnum from (select P_id from dbo.people where bm_id='320000' and mj_id='8') as p left join dbo.qbxx as q on(p.p_id=q.p_id) group by p.p_id