1

I am new to SQL and facing a trouble in grouping.I have a query which gives a table like

time                                          state1
____                                          ______
2015-04-01 00:00:00                             10
2015-04-01 00:00:00                             05
2015-04-01 00:00:00                             08
2015-04-01 01:00:00                             12
2015-04-01 01:00:00                             15
2015-04-01 01:00:00                             30
2015-04-01 02:00:00                             11
2015-04-01 02:00:00                             10
2015-04-01 02:00:00                             27

The query i am using is

SELECT time,state1 
FROM public.block_table 
where time >= '2015-04-01 00:00:00' 
  and time <= '2015-04-01 23:59:59' 
group by time, state1 
order by time;

Instead of this I want to have this grouped

    time                                          state1
    ____                                          ______
    2015-04-01 00:00:00                             23
    2015-04-01 00:00:00                             57
    2015-04-01 00:00:00                             48

I know I am missing a group function.

1 Answer 1

1

Using SUM built in function to get result:

SELECT time,SUM(state1)
FROM Your_table 
WHERE --Your conditions---
GROUP BY time
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.