sql - MySQL Combine multiple rows -


I have a table similar to the following (with most lines and fields):

  Category_id | Client_id | Date | Step 1 1 2009-12-15 First_step 1 1 2010-02-03 Last_step 1 2 2009-04-05 First_STep 1 2 2009-08-07 Last_step 2 3 2009-11-22 First_Step 3 4 2009-11-14 First_step3 4 2010-05-09 last_step I would like to change it so that I can calculate the time between the first and the last steps and finally find the average time between the first and the last steps. Basically, I have to convert something to the table above:  
  category_id | First_date Last_Date 1, 2009-12-15, 2010-02-03 1 2009-04-05, 2009-08-07 2 2009-11-22 NULL 3 2009-11-14, 2010-05-09,  

Any help would be appreciated.

With OMG PONS help, here's the solution:

  SELECT t.category_id, MIN (t.date) AS first_date, when the case is COUNT (*)> gt; = 2 THEN MAX (t.date) as the ELSE NULL END from the last table in the table T group by t.category_id, t.client_id  

Updated on the basis of the question update / explanation:

  SELECT t.category_id, MIN (t.date) as first_date, case Maximum Taka (T.date) = MIN (TDAT) then tap ELSE MAX (t.date) as the expiration date by the table T group TC Category_ id, t.client_id  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -