就是订单,用户表,两个表join查根据userid分组统计的订单数
select user.userid,count(opportunityID) as 订单总数 from UserTable as [user]
join Business_Opportunitys as opportunity
on user.userid = opportunity.userid
group by user.userid
现在我统计出了一个id名下的所有订单了。
呃,现在我想要再写一个查询,类似
select username,count(opportunityID) from UserTable where userid in(
select user.userid,count(opportunityID) as 订单总数 from UserTable as [user]
join Business_Opportunitys as opportunity
on user.userid = opportunity.userid
group by user.userid
)
目的是根据id来查姓名,同时也查到name下的订单总数。(就是把id变成name而已)
显然,上面那个是错的句子查不出来,所以想问问大神们这个东西怎么玩。。
当然,分成两个句子查就不用说了,我只是想了解一下有没有这样的用法
sql join
------解决方案--------------------
你的name肯定对应一个唯一字段,用left join啊,然后把那个唯一字段挂出来就行
------解决方案--------------------
赶紧写你的语句吧