Skip to content Skip to sidebar Skip to footer

How To Select Data Where Sum Is Greater Than X

I am very new to SQL and am using SQLite 3 to run basket analysis on sales data. The relevant columns are the product ID, a unique transaction ID (which identifies the basket) and

Solution 1:

Try

select uniqID, sum(qty) from salesdata groupby uniqID havingsum(qty) >1

"where" cannot be used on aggregate functions - you can only use where on uniqId, in this case.

Solution 2:

if you want to put any condition on the result you get with group by you must use having.

select uniqID, sum(qty) as sumqty from salesdata groupby uniqID having sumqty > 1

you can put any of the condition with having normaly as in where.

having sumqty =1 ,having sumqty <1 ,having sumqty IN (1,2,3) etc..

Post a Comment for "How To Select Data Where Sum Is Greater Than X"