Re: [SQL] 最大值和資料同時顯示問題

作者: standia (匿名)   2016-05-31 01:25:15
select
name , date , score , max(score) over (partition by name)
from raw_data
... 不清楚是不是標準SQL
※ 引述《kuzzz (隱)》之銘言:
: 請問想在select出來的資料內,同時顯示其中某一欄位的max值,有沒有比較好的方式
: EX.
: name. date. score. max_score
: AAA. 5/10. 78. 95
: AAA. 5/12. 95. 95
: AAA. 5/18. 92. 95
: BBB. 5/17. 89. 92
: BBB. 5/21. 92. 92
: 原table資料僅有name, date, score 3個欄位
: 我有想過在原table left join max table
: select raw_data.* from dbo.raw_data
: left join(
: select name, date, score, max_score
: from dbo.raw_data
: group by name, data, score) m_score
: 但是這種方式個人覺得不是很好,而且做到後來筆數可能會增加
: 請問有沒有更方便、更聰明的寫法呢?

Links booklink

Contact Us: admin [ a t ] ucptt.com