• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 540
  • Last Modified:

Agreggate sums in sql

I have a table that looks like:
mydate         value       morning   evening
1/1/2013      10            0                1
1/1/2013      25            0                1
1/1/2013      30            1                0
1/2/2013      50            1                0
1/2/2013      10            0                1
1/2/2013      15            0                1

I would like a select statement that would return the sums of the value by morning and evening...
1/1/2013     30           35
1/2/2013     50           25

I tried the following...

  case when morning=1 then sum(value) else 0 end,
  case when evening=1 then sum(value) else 0 end,
FROM MyDataTable
group by mydate, morning, evening
order by mydate

Thanks in advance...
James Talvy
James Talvy
1 Solution
Aneesh RetnakaranDatabase AdministratorCommented:
  SUM( case when morning=1 then value else 0 end ),
    SUM( case when Evening=1 then Value else 0 end )
FROM MyDataTable
group by mydate
order by mydate
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now