Home > Back-end >  Display four rows as one row (Mysql)
Display four rows as one row (Mysql)

Time:08-08

enter image description here

I have four columns and rows with database how to display as one row with one coloumn Example

  > UID    TIME MIN     MON     MOUT        AIN       AINOUT
        > 14406  2022-08-7   ontime     -          -          -
          14406   2022-8-7      -      ontime      -          -
          14406   2022-08-07     -      -         ontime      -
          14406  2022-08-07     -       -         -          ontime
 
how to make some thin lik this with one uid 
    > UID    TIME MIN     MON     MOUT        AIN       AINOUT
    > 14406  2022-08-7   ontime  on time    ontime   on time

CodePudding user response:

You have to arrange your columns with this query:

 SELECT uid,time,time_search,min(min) as min,min(mout) as mout,min(ain) as ain,min(aout) as aout FROM db_tbl_name GROUP BY uid,time,time_search

This would work fine for your case to get multiple retundant data in one row

CodePudding user response:

For your specific case:

  SELECT d1.uid, DATE(d1.time) time, d1.min, d2.mout, d3.ain, d4.aout
    FROM devices d1, devices d2, devices d3, devices d4
   WHERE d1.min <> '' AND d2.mout <> '' AND d3.ain <> '' AND d4.aout <> '';

Cheers

  • Related