Forums
This topic is locked
show total but only from one column
Posted 24 Oct 2004 20:13:59
1
has voted
24 Oct 2004 20:13:59 Simon Bloodworth posted:
i have a ms database with 4 columns, id, name, purchase_amount, purchase_quantity.Want i want to be able to do is group by using the name, but where it groups one particular user, i would like to be able to add the purchase_amount column together and show it as 1 total.
can this be done?
Replies
Replied 25 Oct 2004 16:40:51
25 Oct 2004 16:40:51 Lee Diggins replied:
Hi Simon
Something like this:
SELECT id, name, SUM(purchase_amount), purchase_quantity column
FROM myTable
GROUP BY name
Digga
Sharing Knowledge Saves Valuable Time!!!
Something like this:
SELECT id, name, SUM(purchase_amount), purchase_quantity column
FROM myTable
GROUP BY name
Digga
Sharing Knowledge Saves Valuable Time!!!
Replied 25 Oct 2004 17:50:59
25 Oct 2004 17:50:59 Simon Bloodworth replied:
works like a charm.
thanks very much for your help. Your a star
regards
simon
thanks very much for your help. Your a star
regards
simon
Replied 25 Oct 2004 18:31:48
25 Oct 2004 18:31:48 Lee Diggins replied:
You're welcome!
Digga
Sharing Knowledge Saves Valuable Time!!!
Digga
Sharing Knowledge Saves Valuable Time!!!
Replied 25 Oct 2004 21:34:32
25 Oct 2004 21:34:32 Simon Bloodworth replied:
another cry for help.
it is working fine as per your advice thanks but what i would like to add in now is be able to count the amount of rows that contain a certain value (name) so it could show me the value amount but also the amount of sales to that particular person.
any advice.
cheers
simon
it is working fine as per your advice thanks but what i would like to add in now is be able to count the amount of rows that contain a certain value (name) so it could show me the value amount but also the amount of sales to that particular person.
any advice.
cheers
simon
Replied 26 Oct 2004 11:31:35
26 Oct 2004 11:31:35 Lee Diggins replied:
Try this, might be what you want:
SELECT COUNT(id) AS 'Quantity', name as 'Name', SUM(purchase_amount) AS 'Purchase Total'
FROM myTable
Group By name
Order By name
Digga
Sharing Knowledge Saves Valuable Time!!!
SELECT COUNT(id) AS 'Quantity', name as 'Name', SUM(purchase_amount) AS 'Purchase Total'
FROM myTable
Group By name
Order By name
Digga
Sharing Knowledge Saves Valuable Time!!!
Replied 26 Oct 2004 15:45:40
26 Oct 2004 15:45:40 Simon Bloodworth replied:
sql is as
SELECT COUNT(ID_Company_name) AS 'Quantity', ID_Username as 'ID_Username', SUM( ID_Purchase_amount) AS 'Purchase Total'
FROM Tbl_UserData
GROUP BY ID_Company_name
ORDER BY ID_Company_name
but am getting the error when tested 'you tried to execute a query that does not include the specified expression 'ID_Username' as part of an aggregate function'
what does it mean?
SELECT COUNT(ID_Company_name) AS 'Quantity', ID_Username as 'ID_Username', SUM( ID_Purchase_amount) AS 'Purchase Total'
FROM Tbl_UserData
GROUP BY ID_Company_name
ORDER BY ID_Company_name
but am getting the error when tested 'you tried to execute a query that does not include the specified expression 'ID_Username' as part of an aggregate function'
what does it mean?
Replied 27 Oct 2004 11:11:46
27 Oct 2004 11:11:46 Lee Diggins replied:
It means that you cannot include the field ID_Username without performing some kind of function on the field - Group By rules I'm afraid.
Can you explain what output you would like to see?
SELECT COUNT(ID_Company_name) AS 'Quantity', ID_Username as 'ID_Username', SUM( ID_Purchase_amount) AS 'Purchase Total'
FROM Tbl_UserData
GROUP BY ID_Company_name
ORDER BY ID_Company_name
Digga
Sharing Knowledge Saves Valuable Time!!!
Can you explain what output you would like to see?
SELECT COUNT(ID_Company_name) AS 'Quantity', ID_Username as 'ID_Username', SUM( ID_Purchase_amount) AS 'Purchase Total'
FROM Tbl_UserData
GROUP BY ID_Company_name
ORDER BY ID_Company_name
Digga
Sharing Knowledge Saves Valuable Time!!!
Replied 27 Oct 2004 11:32:50
27 Oct 2004 11:32:50 Simon Bloodworth replied:
GOt it in the end. used this:
SELECT COUNT(ID_Company_name) AS 'Quantity', SUM( ID_Purchase_amount) AS 'Purchase Total', ID_Company_name AS 'Company'
FROM Tbl_UserData GROUP BY ID_Company_name
ORDER BY ID_Company_name
what this gives allows me to do is show companies registered, the amount of purchases they have made and the total value of these purchases.
It seems to work for the minute.
Once again thanks for your help.
SELECT COUNT(ID_Company_name) AS 'Quantity', SUM( ID_Purchase_amount) AS 'Purchase Total', ID_Company_name AS 'Company'
FROM Tbl_UserData GROUP BY ID_Company_name
ORDER BY ID_Company_name
what this gives allows me to do is show companies registered, the amount of purchases they have made and the total value of these purchases.
It seems to work for the minute.
Once again thanks for your help.