postgresql 9.2 - Confused with sql query -


i have following tables:

customer(login varchar, town varchar) orders (ordno int , login varchar) >>login fk customer combination (id int, ordno int ,product_id int) >>ordno fk orders 

i need show products have been sold in all cities.

example:

insert customer (log1 , ny) (log2, ny) (log3, london) insert orders (1,log1) (2,log1) (3,log3)  insert combination (1,1,1) (2,2,2) (3,3,1)  
  • product 1 sold in ny
  • product 2 sold in ny
  • product 1 sold in london

if available cities ny , london, product must result of query product 1

select  a.productid    combination         inner join orders b             on a.ordno = b.ordno         inner join customer c             on b.login = c.login group   a.productid having  count(distinct a.id) = (select count(distinct town) customer) 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -