別のクエリのグループ化に基づいていくつかの結果をソートする必要があります。別のグループ化の結果としてソート
私は取引があるテーブルを持っており、そのフィールドの1つがストアです。私は、取引日によって注文されたすべての取引を返却したいが、その中で最も多くの取引が最初に記載された店舗に属する取引を持つ必要がある。例えば
:
Date1, Store A, Amount Date1, Store B, Amount Date2, Store A, Amount Date3, Store A, Amount Date3, Store B, Amount Date3, Store B, Amount Date4, Store B, Amount Date5, Store B, Amount Has to be returned as: Date1, Store B, Amount Date3, Store B, Amount Date3, Store B, Amount Date4, Store B, Amount Date5, Store B, Amount Date1, Store A, Amount Date2, Store A, Amount Date3, Store A, Amount
ストアBは、私は内部の窓関数を使用
SELECT *, store_count = count(*) over (partition by Store)
FROM yourtalbe
ORDER BY store_count desc