[SQL]total dans requête sql

Résolu/Fermé
Riwalenn Messages postés 364 Date d'inscription jeudi 25 août 2005 Statut Membre Dernière intervention 16 février 2015 - 9 mai 2007 à 08:32
Riwalenn Messages postés 364 Date d'inscription jeudi 25 août 2005 Statut Membre Dernière intervention 16 février 2015 - 9 mai 2007 à 09:30
Bonjour,

j'ai la requête suivante (faite sur 4 tables) :

SELECT     Company.CompanyName, Company.AccNumber, DeliveryDtls.CreateDate, DeliveryDtls.ProductName, Products.ProductDesc, DeliveryDtls.Quantity, 
                      DeliveryDtls.Quality, Products.Pounds, Products.ProductPrice
FROM         DeliveryDtls INNER JOIN
                      Products ON DeliveryDtls.ProductName = Products.ProductName INNER JOIN
                      Delivery ON DeliveryDtls.DeliveryID = Delivery.DeliveryID INNER JOIN
                      Company ON Delivery.CompanyID = Company.CompanyID
WHERE     (DeliveryDtls.CreateUser = '316') AND (DATEDIFF(dd, DeliveryDtls.CreateDate, '05/07/2007') = 0)
ORDER BY DeliveryDtls.ProductName


elle affiche le résultat suivant :

	Nom de la company	950000	07/05/2007 13:41:00	BRILC900	Brother Inkjet Cartridge LC900 Black	1	AV	0	0
	Nom de la company	950000	07/05/2007 13:41:07	BRILC900C	Brother Inkjet Cartridge LC900 Cyan	1	AV	0	0
	Nom de la company	950000	07/05/2007 14:01:59	BRILC900C	Brother Inkjet Cartridge LC900 Cyan	1	AV	0	0
	Nom de la company	950000	07/05/2007 14:03:59	BRILC900C	Brother Inkjet Cartridge LC900 Cyan	1	AV	0	0
	Nom de la company	950000	07/05/2007 14:04:04	BRILC900M	Brother Inkjet Cartridge LC900 Magenta	1	AV	0	0
	Nom de la company	950000	07/05/2007 14:02:05	BRILC900M	Brother Inkjet Cartridge LC900 Magenta	1	AV	0	0
	Nom de la company	950000	07/05/2007 13:41:12	BRILC900M	Brother Inkjet Cartridge LC900 Magenta	1	AV	0	0
	Nom de la company	950000	07/05/2007 13:41:32	BRILC900Y	Brother Inkjet Cartridge LC900 Yellow	1	AV	0	0
	Nom de la company	950000	07/05/2007 14:02:13	BRILC900Y	Brother Inkjet Cartridge LC900 Yellow	1	AV	0	0
	Nom de la company	950000	07/05/2007 14:04:08	BRILC900Y	Brother Inkjet Cartridge LC900 Yellow	1	AV	0	0


C'est à peu près ce que je voulais mais le problème est que le résultat affiche l'ensemble de mes produits au lieu d'un total par produit... y'a t'il possibilité de faire ça dans ma requête ou pas ?

résultats que j'aimerais avoir :
	Nom de la company	950000	07/05/2007 13:41:00	BRILC900	Brother Inkjet Cartridge LC900 Black	1	AV	0	0
                     	Nom de la company	950000	07/05/2007 13:41:07	BRILC900C	Brother Inkjet Cartridge LC900 Cyan	3	AV	0	0
                      Nom de la company	950000	07/05/2007 14:04:04	BRILC900M	Brother Inkjet Cartridge LC900 Magenta	3	AV	0	0
etc...

1 réponse

Riwalenn Messages postés 364 Date d'inscription jeudi 25 août 2005 Statut Membre Dernière intervention 16 février 2015 101
9 mai 2007 à 09:30
Finalement j'ai trouvé en regardant un peu mes dernières requêtes :
SELECT     Company.CompanyName, Company.AccNumber, DeliveryDtls.CreateDate, DeliveryDtls.ProductName, Products.ProductDesc, 
                      SUM(DeliveryDtls.Quantity) AS total, DeliveryDtls.Quality, Products.Pounds, Products.ProductPrice
FROM         DeliveryDtls INNER JOIN
                      Products ON DeliveryDtls.ProductName = Products.ProductName INNER JOIN
                      Delivery ON DeliveryDtls.DeliveryID = Delivery.DeliveryID INNER JOIN
                      Company ON Delivery.CompanyID = Company.CompanyID
WHERE     (DeliveryDtls.CreateUser = '316') AND (DATEDIFF(dd, DeliveryDtls.CreateDate, '05/07/2007') = 0)
GROUP BY Company.CompanyName, Company.AccNumber, DeliveryDtls.CreateDate, DeliveryDtls.ProductName, Products.ProductDesc, DeliveryDtls.Quantity, 
                      DeliveryDtls.Quality, Products.Pounds, Products.ProductPrice
1