基本上我想選擇特定行值的行基礎。例如我有一個像這樣的表:id name sport score gender1 tom tennis 5 male2 mia football 9 male 3 maria tennis 7 male4 liam swimming 8 female我嘗試過這個 php 腳本:$query = "select sport , score , gender from sprot_table where id = 1" ;$res = $con->query($query) ;$data = $res->fetch_assoc() ;$sport = $data['sport'] ; $sport = $data['score'] ; $sport = $data['gender'] ; $query = "select id , name from sport_table where sport = $sport and gender = $gender and score > $score" ;$con->query($query) ;還嘗試了這個sql代碼:select id , name from sport_table where sport = ( select sport form sport_table where id = 1 ) and gender = ( select gender form sport_table where id = 1 ) and score > ( select score form sport_table where id = 1 ) 我認為它們都沒有優化。我確信應該有更好的方法來做到這一點也許這個例子很簡單但你考慮更復雜的情況
1 回答

牧羊人nacy
TA貢獻1862條經驗 獲得超7個贊
您可以嘗試這個查詢:
select a.* from
(select * from sport_table) a,
(select * from sport_table where id=1)b
where a.sport=b.sport and a.gender=b.gender and a.score>b.score
- 1 回答
- 0 關注
- 142 瀏覽
添加回答
舉報
0/150
提交
取消