Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone
I'm not very good at SQL
I tried to get the amount of sale (promotion item) on each city

SQL
select distinct l.city, p.name as promotion_name, s.count
from location l, promotion p, sale s
where s.locationID=l.id and s.promotionID=p.id
and l.city = 'London' or l.city='Leeds'
or l.city = 'Slough' or l.city='Grays'
and p.name= 'super sale' or p.name='best sale'



Any help ?
Posted
Comments
Magic Wonder 1-Sep-14 5:00am    
Share your table structure to which will help us to help you.

Try this
SQL
select distinct l.city, p.name as promotion_name, count(s.id)
from location l, promotion p, sale s
where s.locationID=l.id and s.promotionID=p.id
and p.name= 'super sale' or p.name='best sale'
Group By l.city, p.name

If you want each city's sale then no need to add in where condition
 
Share this answer
 
Comments
Ryszard50 1-Sep-14 5:18am    
I've got at least 100 cities but I wanna just 4... Query does not give any error but don't give any result.
I' ve done it

I added two more lies

SQL
and l.city in ('London','Leeds')
and p.name in ('Super sale','Best sale')


and it works :)

Thanx anyway for your help guys
 
Share this answer
 
Well, you have not stated the exact structure of the tables. I think you should go through group by in sql[^]

Regards..
 
Share this answer
 
Comments
Ryszard50 1-Sep-14 5:19am    
I was going to put group by anyway...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900