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

sql经典面试题

时间:2014-10-03 15:27:54      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   sp   div   2014   c   log   

1.
表内容:
2005-05-09 胜
2005-05-09 胜
2005-05-09 负
2005-05-09 负
2005-05-10 胜
2005-05-10 负
2005-05-10 负
如果要生成下列结果, 该如何写sql语句?
胜 负
2005-05-09 2 2
2005-05-10 1 2

answer:

bubuko.com,布布扣

select a.rq,a.sheng,b.fu
from (select rq,count(shengfu) as sheng from shengfu  where shengfu=group by rq) a,
(select rq,count(shengfu) as fu from shengfu where shengfu= group by rq)b
where a.rq=b.rq;

 bubuko.com,布布扣

sql经典面试题

标签:style   blog   http   color   sp   div   2014   c   log   

原文地址:http://www.cnblogs.com/huangcongcong/p/4004852.html

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