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