亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用特定行值從表中選擇

使用特定行值從表中選擇

PHP
呼啦一陣風 2023-10-15 17:05:14
基本上我想選擇特定行值的行基礎。例如我有一個像這樣的表: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


查看完整回答
反對 回復 2023-10-15
  • 1 回答
  • 0 關注
  • 142 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號