mysql - SQL GROUPBY & SUM OF A COLUMN -


i have table below structure

+------------+--------+------------------+-----+ |    e_date    | client |       time       | ins | +------------+--------+------------------+-----+ | 2015-06-04 | coma   | 0.00478515625    |  a1 | | 2015-06-04 | coma   | 0.0025390625     |  a1 | | 2015-06-04 | coma   | 0.0              | a1  | | 2015-06-04 | coma   | 0.0              | a1  | | 2015-06-04 | comb   | 0.0115234375     | a2  | | 2015-06-04 | comb   | 1.953125e-4      | a2  | | 2015-06-04 | comb   | 0.0103515625     | a3  | | 2015-06-04 | comb   | 0.0              | a3  | | 2015-06-05 | coma   | 0.00478515625    | a4  | | 2015-06-05 | coma   | 0.0025390625     | a4  | | 2015-06-05 | coma   | 0.0              | a1  | | 2015-06-05 | coma   | 0.0              | a2  | | 2015-06-05 | comb   | 0.010351         | a1  | | 2015-06-05 | comb   | 0.05625          | a1  | +------------+--------+------------------+-----+ 

i looking following output -

+------------+--------+-----+-----------------------------------------------------------+  |    e_date    | client | ins |                        total_time                         | +------------+--------+-----+-----------------------------------------------------------+ | 2015-06-04 | coma   | a1  | sum of time a1 coma date in 'e_date' column | | 2015-06-04 | comb   | a2  | sum of time a2 coma date in 'e_date' column | | 2015-06-04 | comb   | a3  | sum of time a3 coma date in 'e_date' column | | 2015-06-05 | coma   | a1  | sum of time a1 coma date in 'e_date' column | | 2015-06-05 | coma   | a2  | sum of time a2 coma date in 'e_date' column | | 2015-06-05 | coma   | a4  | sum of time a2 coma date in 'e_date' column | | 2015-06-05 | comb   | a1  | sum of time a1 coma date in 'e_date' column | +------------+--------+-----+-----------------------------------------------------------+ 

is right query achieve this?

select e_date, client,ins,sum(ins) total_time group e_date,client 

if understood correctly should answer otherwise i/we needing actual figures of total_time column in expected result :

select e_date,        client,        ins,        (select sum(time)           mytable b          a.e_date = b.e_date                , a.ins = b.ins                , b.client = 'coma') total_time   mytable group  e_date,client,ins  

note : assumed ins in 2nd last row a4 per logic.

sql fiddle


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -