Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Query question
Message
De
20/03/2015 17:56:03
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MySQL
Application:
Web
Divers
Thread ID:
01617030
Message ID:
01617041
Vues:
35
>>My nephew asked for some help on a query and so far I can't seem to think of a good way to do it. Here is his question.
>>
>>A one-to-many relationship where the parent table is a list of customers and the child table is a list of things they've bought. It's easy enough to select customers who have bought a television. It's also simple to select customers who have bought a television or a couch. But how do I select customers who have bought both a television and a couch? The following is returning customers who have bought both or one of the items:
>>
>>
>>I don't have data to test with and I was hoping someone could had an idea.
>>
>>Thanks
>
>create table #Customers (CustomerID int, CustomerName varchar(50))
>create table #Products (ProductID int, ProductName varchar(50), Price Money)
>create table #Sales (ProductID int, CustomerID int, Quantity int)
>
>insert into #Customers (CustomerID, CustomerName) values (1, 'Robert'), (2, 'James'), (3, 'Anderson')
>insert into #Products (ProductID, ProductName, Price) values (1, 'Apple', 1), (2, 'Orange', 5.3), (3, 'Grapes', 2)
>insert into #Sales (ProductID, CustomerID, Quantity) values (1, 1, 1), (1, 2, 3), (2, 1, 2), (3, 1, 5), (2, 2, 2), (1, 1, 1)
>
>select		distinct
>		Cust.CustomerId, 
>		Cust.CustomerName
>	from	#Customers Cust
>	inner	join #Sales Sp1 On Cust.CustomerId = Sp1.CustomerId and Sp1.ProductID = (select ProductID from #Products where ProductName = 'Orange')
>	inner	join #Sales Sp2 On Cust.CustomerId = Sp2.CustomerId and Sp2.ProductID = (select ProductID from #Products where ProductName = 'Apple')
>
>drop table #Customers
>drop table #Products
>drop table #Sales
>
Hi Hugo,

and now - generic for n items ....

w/o macro or the like
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform