码迷,mamicode.com
首页 > 数据库 > 详细

SQL SERVER练习

时间:2015-08-17 13:39:55      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:

使相同分类中n的值加上m的值:
技术分享

1
select 分類,mAn=sum(數量) from A where (名稱=m OR 名稱=n) and 2 3 分類 in( 4 --帶m和n的組至少有一組 5 select an.分類 from 6 ( 7 select 分類,countm from 8 (select 分類, countm=count(名稱) from A where 名稱=m group by 分類) cm 9 where cm.countm>=1 10 ) am right join 11 12 ( 13 select 分類,countn from 14 (select 分類, countn=count(名稱) from A where 名稱=n group by 分類) cn 15 where cn.countn>=1 16 ) an on an.分類=am.分類) 17 18 group by 分類

 

SQL SERVER练习

标签:

原文地址:http://www.cnblogs.com/slmdr9/p/4736232.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!