看板 Database 關於我們 聯絡資訊
※ 引述《fantasywater (狂想)》之銘言: : ※ 引述《flakchen (flak)》之銘言: : : 少了 where T1.dno=T2.dno : : 因為少了那一句的關係 : ----------------------------------------------------- : 結果如下: : mysql> Select Distinct T1.dno,T1.Salary : : -> From employee as T1 : : -> Where salary=(select T2.salary : : -> from employee as T2 : where T1.dno=T2.dno : : -> group by T2.dno : : -> order by count(*) desc : : -> limit 1); : +------+--------+ : | dno | Salary | : +------+--------+ : | 5 | 30000 | : | 1 | 55000 | : | 4 | 43000 | : +------+--------+ : 3 rows in set (0.00 sec) : -------------------------------------------------------- : 會取到下面箭頭所指示的那三筆資料 : 裡面的 order by count(*) desc 不知為何似乎沒有作用到 : 而取到最少出現的那幾筆資料 : +------+--------+ : | dno | salary | : +------+--------+ : | 5 | 30000 | <--- : | 5 | 25000 | : | 5 | 25000 | : | 5 | 38000 | : | 1 | 55000 | <--- : | 4 | 43000 | <--- : | 4 | 25000 | : | 4 | 25000 | : +------+--------+ 第一個可以用暫存資料表寫出來~ <MS-SQL> select dno,salary,count(salary)'頻率' into #table1 from #table group by dno,salary go select dno,salary,頻率 from #table1 t1 whereA 頻率=(select max(頻率) from #table1 where t1.dno =t2.dno) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.127.194.122
fantasywater:這麼久了居然還有人回!! 05/26 23:24