Select SUM(CASE When CPayment='Cash' Then CAmount Else 0 End) as CashPaymentAmount, SUM(CASE When CPayment='Check' Then CAmount Else 0.
I would change the query in the following ways: Do the aggregation in subqueries. This can take advantage of more information about the table.
SUM(CASE WHEN id>=10 THEN id ELSE 0 END) . New Book: Beginner Database Design & SQL Programming Using Microsoft SQL Server.
I think you do not need the last column in your GROUP BY clause: SELECT dads-space.com, dads-space.comme.
I'm trying to recreate the following SQL CASE statement in Tableau. SUM( CASE WHEN Goal_Met = 1 THEN 1 ELSE 0 END) AS Yes.
See how easily you can learn how to use CASE WHEN with SUM by practising SQL queries online. Join over 30 users who finished Vertabelo Academy.
SQL Related Articles: Sum Calculations in select statement and filtering based on SUM(CASE WHEN dads-space.com = 'Charge' THEN dads-space.com END) AS Charges.
For some reason my sample output above posted vertically when I pasted it as a horizontil table, not sure why it did that. The output should.