The Way to Programming
The Way to Programming
I’m rather new to SQL and I can’t figure out a decent way to do this query – I need to find out what ‘Name’ has the largest ‘in’ number.
By the looks of this table it’s “SS” (5+2) so I need the query that would display “SS”. Also the timestamp is important because the query only has to find the largest ‘Name’ in August.
I hope you can understand what I mean. Could anyone please help me with this ?
Timestamp; Name; in; out 2014-08-01 09:30:00;VV;1;2 2014-08-02 09:30:00;SS;5;6 2014-08-03 09:45:00;VV;3;4 2014-08-01 09:45:00;SS;2;3 2014-05-01 09:45:00;KK;2;3
It is going to be in the form of:
SELECT column_name [, column_name ] FROM table1 [, table2 ] WHERE column_name OPERATOR (SELECT column_name [, column_name ] FROM table1 [, table2 ] [WHERE])
Using sum and max functions.
There is a great site that allows you to test things out:
http://www.w3schools.com/sql/trysql.asp?filename=trysql_func_max
Can you provide the table and field names that will be used (not the data, just the table is SALES, field names are x,y,z …? That way the example code will need less work
Table is named ‘stats’ and field names are like in the first post. (Timestamp, Name, in, out). That’s what you mean right ? The names are not that important I’m sure if I’ll have the syntax I can fix it to work with my db. Thanks again for your effort.
A bit too late maybe, but hope it helps..
SELECT name ASname
, SUM(in
) ASsum_in
FROM temp GROUP BYname
ORDER BYsum_in
DESC;
Sign in to your account