+ 6
conditions based on conditions
how do I make a condition based on another condition using the group by having commands. show total sales for each country (multiple rows that have country as attribute) which have at least two users using Yahoo email. having trouble with the at least two users part. I need to group an aggregat sales function by country and have a condition maybe like count(email='%@yahoo%') > 2 or something that will let me form a condition and then base another condition off the results of the first
6 odpowiedzi
+ 1
Try using a sub query for your condition
SELECT SUM(SALES) FROM table where (SELECT count(*) FROM TABLE GROUP BY country HAVING email IN ('%@yahoo%)) >2 GROUP BY country
0
select * from table where ( select count) from table group by country having email='%@yahoo%')>2 group by country
0
select sum(sales),country
from <tablename>
groupby country
having count(email like"%@yahoo%")>2;
- 1
use AND instead of ,
- 1
what do you mean? I need it to group by country for only those countries that have more than 2 Yahoo emails.
- 2
try select colum name from table name where colum name, colum name;