0

I have a table

Date trial value
2020-12-10 false 100
2020-12-10 true 200
2020-12-11 false 150
2020-12-11 true 350

I want result

Date total value1
2020-12-10 300 100
2020-12-11 500 150

Where value1 is the value when trial=false. what is the SQL query to do this? Thanks in advance

3 Answers 3

1

You can use conditional aggregation:

select date, sum(value),
       sum(case when trial = 'false' then value end) as value1
from t
group by date;

Note: If your database support boolean values and trial is boolean, then:

       sum(case when trial then value end) as value1
Sign up to request clarification or add additional context in comments.

Comments

1

You can use cnoditional aggregation:

select date, sum(value) as total,
    sum(case when trial = 'false' then value else 0 end) as value1
from mytable
group by date

Comments

0

You can use the case statement in select clause:

SELECT
..., case when ColumnA > x then ColumnA else ColumnB end as C from ...

for more details visit : http://msdn.microsoft.com/en-us/library/ms181765.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.