已經詢問了這些問題的很多變體,但似乎找不到適合我的表的變體。我有三列pd,stm和salesincrease。我想找到每個stm的銷售增量的最大值。顯示最大groupby與兩列的行sql
pd stm salesincrease
Chamomile Central 801
Caffe Mocha Central 752
Earl Grey Central 725
Colombian East 975
Lemon East 573
RegEspresso East 531
Caffe Mocha East 356
Lemon West 667
DeEspresso West 664
Colombian West 628
Darjeeling West 623
我得到的問題是,我做的:
select stm, pd, max(salesincrease) as maxsales from
table
group by stm, pd;
,並沒有顯示出正確的結果。我也試過:
select stm, max(salesincrease) as maxsales from
table
group by stm;
這顯然表明了STM和最大值,但在那裏沒有一個錯誤,我不能拿到產品名稱
理想我想這樣的輸出:
pd stm salesincrease
Chamomile Central 801
Colombian East 975
Lemon West 667
'partition by stm'我認爲 – Laurence 2014-09-21 20:10:43
@Laurence。 。 。謝謝。我誤解了這個問題。 – 2014-09-21 20:16:40