2. 优化使用join 语句
select a.user_name , b.timestr , b.kills
from user1 a
join user_kills b on a.id = b.user_id
join user_kills c on c.user_id = b.user_id
group by a.user_name , b.timestr , b.kills
having b.kills = MAX(c.kills)
select a.user_name , b.timestr , b.kills
from user1 a
join user_kills b on a.id = b.user_id
join user_kills c on c.user_id = b.user_id
group by a.user_name , b.timestr , b.kills
having b.kills = MAX(c.kills)
2019-06-25
1. 使用子查询语句:
select a.user_name,b.timestr,b.kills from user1 as a left join user_kills as b on a.id = b.user_id
where b.kills = (select max(c.kills) from user_kills as c where b.user_id = c.user_id);
select a.user_name,b.timestr,b.kills from user1 as a left join user_kills as b on a.id = b.user_id
where b.kills = (select max(c.kills) from user_kills as c where b.user_id = c.user_id);
2019-06-25
UPDATE user1,user2 set user1.over = '齐天大圣' WHERE user1.`user_name` = user2.`user_name`; 这样也能操作
2019-05-03
最赞回答 / 幸福是可积的
这个具体得看执行计划,join两表的连接条件有索引的话,数据库会根据连接条件获取满足条件的数据,并进行相应的优化,一般来说数据量小的话,走不走索引影响不大,数据量达到一定级别且连接条件的字段有索引,数据库就会走索引
2019-02-21
已采纳回答 / 久伴兔兔宝宝
left join即left outer join是左连接,若有A\B两张表,意思是查询出A表的全部数据和与之对应的B表数据,B表中没有的数据就用null代替;而right outer join是右连接,意思是查询出B表的全部数据和与之对应的A表数据。怎么会划等号?查出的数据都不一样的
2019-02-16
最新回答 / wuloves
参考这个吧 , 被你这个问题问的我也很懵逼 , 我找了这个文档链接 , 里面也没见到使用 is not null的 https://www.cnblogs.com/logon/p/3748020.html
2019-02-01
a表1,2,3.
b表2,3,4
全连接结果:
1,null
2,2
3,3
null,4
where 选中带有null的值
1,null
null,4
b表2,3,4
全连接结果:
1,null
2,2
3,3
null,4
where 选中带有null的值
1,null
null,4
2019-01-24