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

SQL开发技巧

时间:2015-07-18 16:52:38      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

1. 同一属性的多值过滤

2. 如何在子查询中匹配两个值

准备数据

user1表

技术分享

user_kills

技术分享

join方法

select a.user_name, b.timestr, b.kills from user1 a join user_kills b on a.id = b.user_id
join (select user_id,max(kills) as cnt from user_kills group by user_id) c
on b.user_id = c.user_id and b.kills = c.cnt

where子句方法

select a.user_name, b.timestr, b.kills from user1 a join user_kills b on a.id = b.user_id
where (b.user_id,b.kills) in (select user_id,max(kills) as cnt from user_kills group by user_id);

 

SQL开发技巧

标签:

原文地址:http://www.cnblogs.com/phpfans/p/4657088.html

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