さまざまな範囲の値の数を取得するクエリを作成しようとしています。
私のテーブルに「Name」という列と「Value」という数値の別の列があるとします。
「値」列は、1から100までの値を取ることができます。
現在、私は次のようなクエリを書いています
select count(1) from table where value between 1 and 10
union all
select count(1) from table where value between 11 and 80
union all
select count(1) from table where value between 81 and 100.
クエリは結果を表示しますが、veeeeeerrrrrySLOWを実行しているようです。
これを行うためのより良い方法はありますか?
他の列もあるので、「値」列の値に基づいてテーブルを分割できないことを覚えておいてください。
編集
上記のクエリを次のように変更します
select count(distinct names) from table where value between 1 and 10
union all
select count(distinct names) from table where value between 11 and 80
union all
select count(distinct names) from table where value between 81 and 100.