Question
-
Topic
-
SQL Joins,Subqueries. One Table.
LockedFirst, I am NOT an sql expert or anywhere close to that. I’m attempting to put the work portions on the Database backend as there is less cpu throttling done there than on a cgi frontend, here’s what I need to accomplish:
Have a table with something like this for columns:
uid, ownerid, name, field1, field2, datefield, field3, field4, field5, field6, field7 field8, moneyfield.
What I would like to accomplish:
A select that grabs all the fields in all the rows, (except uid), and groups by ownerid, then adds a row that sums the moneyfields for each ownerid.
I have tried things such as:
SELECT *, sum(moneyfield)as total from table, order by ownerid.
Of course this brings up errors. I have tried being more explicit and naming my fields instead of using * (since I want to drop the uid in my resultset..) but even doing something like
SELECT field, field, field,…, sum(moneyfield) as total from table order by ownerid, otherfields…; I get errors…and when I get rid of all syntax and omitted field errors.. I get JUST a sum line. I don’t want a sum line, and don’t understand a thing about JOINS, UNIONS, etc…despite having investigated some tutorials..which just made me more confused.
Any suggestions?
(I can handle this issue in Perl, but again, I’m running up against cpu throttling issues in the CGI side of things that aren’t in the DB backend.)