mysql - Need to select sum of the same field in SQL with diffrent Conditions -
i have 2 tables used select sum of same field different conditions tried query follows result showing same in 2 fields
select sum( s.message_count) total,(case when s.dlr_status = 'delivrd' sum( s.message_count) end ) delivered `sent` s join `track` t on t.track_id = s.track_id group t.sent_type
any appreciable thank you
move sum
outside of case..when
projection, , completeness, return 0 in 'else'. you'll need sent_type
column in select in order group it.
select t.sent_type, sum(s.message_count) total, sum(case when s.dlr_status = 'delivrd' s.message_count else 0 end) delivered `sent` s join `track` t on t.track_id = s.track_id group t.sent_type;
Comments
Post a Comment