conditions based on conditions | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

30th Sep 2016, 4:05 AM
Facundo Ferreira
Facundo Ferreira - avatar
6 Answers
+ 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
22nd Nov 2016, 12:25 AM
Kasem Chaisieng
Kasem Chaisieng - avatar
0
select * from table where ( select count) from table group by country having email='%@yahoo%')>2 group by country
2nd Dec 2016, 5:34 AM
kajal joshi
0
select sum(sales),country from <tablename> groupby country having count(email like"%@yahoo%")>2;
22nd Jan 2017, 11:18 PM
mahendra mahajan
mahendra mahajan - avatar
- 1
use AND instead of ,
1st Oct 2016, 10:31 PM
Deno Däumling
Deno Däumling - avatar
- 1
what do you mean? I need it to group by country for only those countries that have more than 2 Yahoo emails.
1st Oct 2016, 10:48 PM
Facundo Ferreira
Facundo Ferreira - avatar
- 2
try select colum name from table name where colum name, colum name;
1st Oct 2016, 2:02 PM
Chukwudi Igbojionu
Chukwudi Igbojionu - avatar