2
Name    Value   AnotherColumn
-----------
Pump 1  8000    Something1
Pump 1  1000    Something2
Pump 1  3000    Something3
Pump 2  3043    Something4
Pump 2  4594    Something5
Pump 2  6165    Something6

In this table I want to group by on Name column and give output as name,value_exist.

value_exist will be 1 if 1000 is present in any of the value column for that name group. so the output will be:

Name    value_exist
-----------
Pump 1  1
Pump 2  0 

3 Answers 3

2

Maybe something like this:

select name, MAX(CASE WHEN value=1000 THEN 1 ELSE 0 END) as value_exist
from your_table
group by name
Sign up to request clarification or add additional context in comments.

Comments

1

One more :

select name , max(if(value=1000,1,0)) as value_exist
from table 
group by name;

Comments

0
select name, sum(value = 1000) as value_exist
from your_table
group by name

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.