sql - MySQL add total column -


I have to ask this DB to get each line, but one of the column values ​​of the results will also be SUM I can use php to get the total value, but then I need to run two loops, one to get the total (which goes to the top above the result). So I like the query to capture it and make just one "total" row, but the way I worked on it is with a subquiri, which is basically a repeat of the original query. Is there a better way?

  SELECT CONCAT (u.firstname, '', u.lastname) Name, UID, SDS, S. Shift start, s. Shift, parses with SELECT (TIMEEDIFF (shiftied, shiftstart)) / 3600 WHERE id = '$ user' and between date (shiftstart) '$ start' and '$ end' between changes) Total INNER Connect the user to .id = u.id) works as above and the date (shiftstart) between '$ start' and 'end-end' via SAID = '$ user' and 'shift start' as output. :    Name ID Description ShiftStart, respectively, which total user Juicer Stuff 2009-01-05 07:45:00 2009-01-05 12:15:00 39.5000 users who have ginger stuff 2009-01- 05 13:00:00 2009-01-05 17:00:00 39.5000 Which user gambler stuff 2009-01-06 07:45:00 2009-01-06 10:45:00 39.5000 User shoe stuff 2009-01- 06 10:45:00 2009-01-06 12:45:00 39.5000 Which User Juicer Stuff 2009-0 1-06 13:30:00 2009-01-06 14:30:00 39.5000 Users Who Ginger Stuff 2009-01 -06 14:30:00 2009-01-06 17:00:00 39.5000 User Shoe Shoe 2009-01-07 09:45:00 2009-01-07 14:00:00 39.5000 Users Who Ginger Stuff 2009-01 -07 15:00:00 2009-01-07 17:00:00 39.5000 user shoe store 2009-01-08 08:00:00 2009-01-08 12:15:00 39.5000 user user guller staff 2009-01-08 13:15:00 2009-01-08 17:00:00 39.5000 Which Users Ginger Stuff 2009-01-09 07:45:00 2009-01-09 10:45:00 39.5000 Users Who Ginger Stuff 2009-01-09 11:45:00 2009-01-09 15:15:00 39.5000 Which Users Ginger Stuff 2009-01-09-15: 15: 00 2009-01-09 17:00:00 39.5000  

I am what I want, but probably not the best way to get it.

Supports a special group-modifier called MySQL.

  SELECT CONCAT (u First name, '', u.stemann) name, U.id, s.description, s.shiftstart, s.shiftend, SUM (TIME_TO_SEC (TIMEDIFF (shiftind, shiftstart ))) / 3600 Total changes Join INNER user (s.id = u.id) on U where is .id =? And between DATE (shiftstart)? And? Group U.ID, S. Shift start by shift start with roll order;  

Comments