三个数据表:
表一types:
typeid typename
1 ...
2 ...
3 ...
……表二product:
productid typeid productname
1 1 ……
2 1 ……
3 3 ……
……表三news:
newsid typeid newsname
1 1 ……
2 1 ……
3 2 ……
……现在要统计表二和表三中属于每种分类的条目
我表一加表二可以统计,得到
typeid count(product.*) as product_num
1 ……
2 ……
……表一加表三也可以统计这么统计现在我想用一个sql得到
typeid count(product.*) as product_num count(news.*)as news_num
1 …… ……
2 …… ……
……但是总是得不到正确的结果
哪位兄弟指导一下?谢谢!
表一types:
typeid typename
1 ...
2 ...
3 ...
……表二product:
productid typeid productname
1 1 ……
2 1 ……
3 3 ……
……表三news:
newsid typeid newsname
1 1 ……
2 1 ……
3 2 ……
……现在要统计表二和表三中属于每种分类的条目
我表一加表二可以统计,得到
typeid count(product.*) as product_num
1 ……
2 ……
……表一加表三也可以统计这么统计现在我想用一个sql得到
typeid count(product.*) as product_num count(news.*)as news_num
1 …… ……
2 …… ……
……但是总是得不到正确的结果
哪位兄弟指导一下?谢谢!
解决方案 »
- asp.net webfrom路由设置问题
- asp.net 连接Oracle数据库提示"The 'OraOLEDB.Oracle' provider is not registered"
- ScriptManager不是已知元素?原因是网站存在编译错误!
- 一个退出登录的问题
- 关于网站 全球化 实现多语言的问题
- FormsAuthentication.RedirectFromLoginPage(userId, false)
- 在DataGrid中在table中排版,为什么LinkButton的OnClick事件或DataGrid的其他事件都不响应呢
- repeater控件中包含radiobuttonlist控件,如何使radiobuttonlist绑定数据
- asp.net 我想读取一个.htm的文件,该怎么写这个代码呢
- 请懂得的高手帮忙!
- sql server中的text类型可以存储多少个字符?
- 一个应该很简单的问题,大哥们帮忙
a.product_num ,
count(news.newsID) as news_num
from (
select types.TypeID
,count(product.productid) as product_num
from types
inner join product on product.TypeID = types.TypeID
group by types.TypeID
) as a
inner join news on news.TypeID = a.TypeID
group by a.TypeID,a.product_num