Home > database >  SQL multi-line sum problem
SQL multi-line sum problem

Time:01-14

Consult everybody the teacher, I think total amount, but the total number of members want to charge a single aggregate, should how to write

Select the project, the sum (amount) as the summary from shouruzhichu where brand='good Fried o' and the & lt;> 'members' top-up' GROUP BY project order BY summary
I will only written out, not a list of more

CodePudding user response:

 
The CREATE TABLE # A (
The VARCHAR (20),
The value of the INT
)
# INSERT INTO A VALUES (' take-away ', 500)
# INSERT INTO A VALUES (' take-away ', 500)
# INSERT INTO A VALUES (' members' top-up ', 500)
# INSERT INTO A VALUES (' take-away ', 500)
# INSERT INTO A VALUES (' members' top-up ', 500)
# INSERT INTO A VALUES (' take-away ', 500)

SELECT
The SUM ((CASE WHEN a. the='members' top-up' THEN 0 ELSE a. amount END)) non-members top-up,
The SUM ((CASE WHEN a.='members' top-up' THEN a. the amount the ELSE 0 END)) member prepaid phone
The FROM # aa

DROP TABLE # A

Is the effect?
Non-members top-up member prepaid phone
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
2000, 1000,
  • Related