年齢に基づいてデータをグループ化しようとしています。私は次のデータベース選択を使用します:
select * from (
select 0 range_start, 11 range_end, '0-10 days' date_description from dual union
select 11, 21, '11-20 days' from dual union
select 21, 31, '21-30 days' from dual union
select 31, 99999, '31+ days' from dual) date_helper
left outer join table
on table.date <= date_helper.range_start*-1 + sysdate
and table.date > date_helper.range_end*-1 + sysdate
次に、date_description列に基づいてグループを作成します。レコードがない場合でも、そのグループに含まれるすべてのグループを表示するようにしています。レコードがない場合は、値を0にして、グループを出力します。