Reputation: 85
this is my sql code... code works fine and return data but if i try to sum then it throws error.. I am using C#.. I want to sum the left1 and right1 column
SELECT Left1, Right1, Left_cf, Right_cf, case when Paid=0 then 'Unpaid' else 'Paid' end as 'Status' FROM BinaryWallet WHERE App_ID = "1000"
with sum :
SELECT sum(Left1), sum(Right1), Left_cf, Right_cf, case when Paid=0 then 'Unpaid' else 'Paid' end as 'Status' FROM BinaryWallet WHERE App_ID = " 1000 "
Upvotes: 0
Views: 98
Reputation: 10285
try like this
SELECT sum(Left1), sum(Right1), Left_cf, Right_cf,
case when Paid=0 then 'Unpaid' else 'Paid' end as 'Status'
FROM BinaryWallet WHERE App_ID = " 1000 "
group by Left_cf, Right_cf,Paid,Vid
Upvotes: 1
Reputation: 26
You must use group by left_cf,Right_cf,Paid
In sql Sum statement works with group by
if you add the bottom of your code
Group by left_cf,Right_cf,Paid
your code will work.
Upvotes: 1
Reputation: 2135
SELECT sum(Left1), sum(Right1), Left_cf, Right_cf,
case when Paid=0 then 'Unpaid' else 'Paid' end as 'Status'
FROM BinaryWallet WHERE App_ID = " 1000"
GROUP BY Left_cf,Right_cf,Paid
Upvotes: 1