Group, add and total.

Dúvidas, dicas e truques de SQL, Select, Update, Delete, cláusulas, operações com joins, Funções em SQLs, etc
Post Reply
User avatar
tfg
Rank: Analista Júnior
Rank: Analista Júnior
Posts: 83
Joined: Mon, 03 May 2004 3:38 pm
Location: Novo Hamburgo - RS

I want to add a value per group but I also want to receive the total of everything in the same query. It's possible ?

Something like this:

Select all

AAA    50 
BB     30 
total  80 
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Group, account and still gives the total

is in the user scott ...

Select all

SELECT  
  DECODE(GROUPING(DEPTNO),1,'TOTAL----->',DEPTNO) DEPTNO, 
  COUNT(*) QTD 
FROM EMP 
GROUP BY ROLLUP(DEPTNO) 
/ 
 
 
DEPTNO                               QTD 
--------------------------------- ---------- 
20                                      4 
30                                      6 
50                                      1 
TOTAL----->                            11
Post Reply
  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 12 guests