看板 PHP 關於我們 聯絡資訊
※ 引述《sunz5010 (FoFo)》之銘言: : 我想select一段資料 : 姓名|日期|分數 : ----------------- : 小明|12/1|80 : 大華|12/1|70 : ----------------- : 小明|11/1|70 : 大華|11/1|75 : ----------------- : 小明|10/1|60 : 大華|10/1|80 : 我想找出 : 12/1分數>11/1分數>10/1分數 的人 : 按照上面的數據、他應該會搜尋出小明 : 因為小明(12/1,80)>(11/1,70)>(10/1,60) : 想請問一下、這樣子mysql的語法應該怎麼下呢 我照你的格式建了一張表來測試,如下 mysql> select * from test01; +------+-------+-------+ | name | date | score | +------+-------+-------+ | AA | 12/01 | 80 | | BB | 12/01 | 70 | | AA | 11/01 | 70 | | BB | 11/01 | 75 | | AA | 10/01 | 60 | | BB | 10/01 | 80 | +------+-------+-------+ 6 rows in set (0.00 sec) 使用以下的 SQL 敘述 select name from test01 as m where (select score from test01 as a where date='12/01' and m.name=a.name) > (select score from test01 as b where date='11/01' and m.name=b.name) and (select score from test01 as c where date='11/01' and m.name=c.name) > (select score from test01 as d where date='10/01' and m.name=d.name) group by name 結果如下: +------+ | name | +------+ | AA | +------+ 1 row in set (0.00 sec) 或許語法不是很高明,不過確實可以達成目的 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.41.8.19