アプリ版:「スタンプのみでお礼する」機能のリリースについて

select A,B from tableC group by A, B
として、最後の1行に合計を出すSQLを作りたいのですが、
可能でしょうか?

A 回答 (2件)

Oracleの環境がないので、テストしていませんが、以下のSQLを試してみてください。



(1)グループ毎の最後に件数&一番最後に総件数を得る
select A,B,count(*) as cnt
from tableC group by rollup(A, B)

(2)一番最後に総件数を得る
select * from(
select A,B,count(*) as cnt
from tableC group by rollup(A, B)) as x
where not(A is not null and B is null)
    • good
    • 0

集約項目毎の件数と、総合計を取りたいのであれば、


単純にとって来れば良いと思うのですが・・・。

select A, B, count(*) from tableC group by A, B
union
select '', '', count(*) from tableC
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!