Posts: 18
Location: Essex, United Kingdom
|
Could someone please help with my sql query. I have been at it for two days now, and am now running out of time. I have two tables as below.
Table 1 (data)
ContentID----Quantity
---------------------
prd_00001------1
prd_00002------2
prd_00003------3
prd_00001------5
prd_00002------6
prd_00003------7
Table 2 (IDs)
ContentID--------Name--------Language
----------------------------------------
prd_00001-------Product 1--------UK
prd_00002-------Product 2--------FR
prd_00003-------Product 3--------UK
What i am trying to achieve is a table showing unique ContentIDs, the name for that Content ID, it's Language and a sum of Quantity.
i.e.
ContentID----Name---------Language---Quantity
------------------------------------------------
prd_00001----Product 1--------UK----------6
prd_00002----Product 2--------FR----------8
prd_00003----Product 3--------UK---------10
The SQL query i have finally given up on is
SELECT d.ContentID, c.Name, c.Language, SUM(Quantity) From data d, IDs c WHERE c.ContentID = d.ContentID GROUP BY d.ContentID
this is throwing errors about values not being part of an aggregated function. I have tried to research the use of aggregated functions, but being on a tight deadline, i have not been able to digest it properly. I now understand what aggregate functions are, but cannot seem to work out what to use when querying more than one field. To be honest, at this stage it is going straight over my head. I fully intend to research it more, but in the mean time, is anyone able to provide me with the correct solution. Also, is it possible to order on Quantity Desc. I tried with a different query, but it doesn't seem to like it when the results are grouped
|