Re: [SQL ] 如何找出頻率最高的查詢一問

看板Database作者 (hasio)時間17年前 (2008/05/26 21:15), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串10/10 (看更多)
※ 引述《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

05/26 23:24, , 1F
這麼久了居然還有人回!!
05/26 23:24, 1F
文章代碼(AID): #18EhVsV3 (Database)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 10 之 10 篇):
文章代碼(AID): #18EhVsV3 (Database)