sambit.albus
sambit.albus

Reputation: 250

Create a Summarized report using Mysql Query

My Table is like

| Cat | Sub_Cat | Amt|
______________________
 X    | Y       | 200
_______________________
 X    | Z       | 1000
__________________________
 X    | Y       | 300
__________________________
 A    | B       | 600

Now i want to write a query where i can Show a summarized report which is grouped by category like this output

| Cat | Sub_Cat | Amt|
______________________
 X    | Y       | 500
_______________________
 X    | Z       | 1000
__________________________
 A    | B       | 600

Kindly help

Upvotes: 1

Views: 58

Answers (2)

Michael Kazarian
Michael Kazarian

Reputation: 4462

select t.cat, t.sub_cat, sum(t.amt) from table t
group by t.cat, t.sub_cat

Upvotes: 2

Stephan
Stephan

Reputation: 8090

Try this:

SELECT
  Cat,
  Sub_Cat,
  SUM(Amt) as total
FROM
  my_table
GROUP BY
  Cat,
  Sub_Cat

Upvotes: 2

Related Questions