I have a problem with an SQL Query.
I have been tasked to display the names of employees who have sold to at least 4 different stores.
I have written the following query:
select EmpCode from Items
group by EmpCode
having COUNT (EmpCode)>=4
order by EmpCode desc;
But I am still getting values for those employees who have sold to the same store, the result being:
EMPCODE
-------
E4
E3
E2
E1
I am made aware that others have been getting various other answers, but the most common is just 1 value being returned.
The table contains “ItemNo, StoreNo, ItemDesc, Quant, Units, ReorderNo, Price, EmpCode”
The table has a total of 34 records with 0 null values.
Multiple employees have sold multiple number of items to various different stores.
But the full table shows that only E3 has sold to 4 different stores
whilst others have sold to either the same store, two stores or three stores.
I wish to show that E3 is the only Employee to have sold to 4 different stores.
Any help would be appreciated, thanks
You should use
COUNT(DISTINCT StoreNo):