来个高人~~ 关于SQL的3张表的整合~~ 在线等 ~

q49442315 2010-07-27 10:03:44
1.select store.id,storename ,store.returnstate
as rate ,count(comments.storeid)
as commentcount from store

left join comments on
comments.storeid=store.id
group by store.id
order by rate asc


2.select store.id, count(banner.storeid)
as bannercount from store

left join banner on
banner.storeid=store.id
group by store.id
order by id asc

只要在一个查询结果集里面显示count(comments.storeid),count(banner.storeid),store.id,store.storename就可以了
...全文
42 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
永生天地 2010-07-27
  • 打赏
  • 举报
回复
。。。今天忘吃药了
[Quote=引用 1 楼 xys_777 的回复:]
SQL code
select
count(comments.storeid),count(banner.storeid),store.id,store.storename

from store left join comments on
comments.storeid=store.id
left join banner on
banner.storeid=store.id
……
[/Quote]
pt1314917 2010-07-27
  • 打赏
  • 举报
回复
select a.id,a.storename,a.commentcount,b.bannercount from 
(select store.id,storename,count(comments.storeid)as commentcount from store
left join comments on comments.storeid=store.id
group by store.id)a,
(select store.id, count(banner.storeid)as bannercount from store
left join banner on banner.storeid=store.id
group by store.id)b
where a.id=b.id
永生天地 2010-07-27
  • 打赏
  • 举报
回复
select 
count(comments.storeid),count(banner.storeid),store.id,store.storename

from store left join comments on
comments.storeid=store.id
left join banner on
banner.storeid=store.id
group by store.id
order by rate,id

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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