Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Move GROUP_CONCAT's comma values to columns

Move GROUP_CONCAT's comma values to columns

Scheduled Pinned Locked Moved Database
comquestionannouncement
3 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    Hi, I am using below code to display times as Pivot table grouped by date, this is basically for fingerprint attendance... I am getting what I want like this: 2012-06-03 10:23:30,10:23:32,10:24:05,10:24:07,10:24:24,10:24:26 How can I make the comma separated values displayed in columns instead of comma so it will be something like this created_date - time1 - time2 - time3 - time4 --- etc this is the code:

    SELECT created_date, GROUP_CONCAT(created_time)
    FROM fingerprint
    GROUP BY created_date

    Technology News @ www.JassimRahma.com

    J 1 Reply Last reply
    0
    • J Jassim Rahma

      Hi, I am using below code to display times as Pivot table grouped by date, this is basically for fingerprint attendance... I am getting what I want like this: 2012-06-03 10:23:30,10:23:32,10:24:05,10:24:07,10:24:24,10:24:26 How can I make the comma separated values displayed in columns instead of comma so it will be something like this created_date - time1 - time2 - time3 - time4 --- etc this is the code:

      SELECT created_date, GROUP_CONCAT(created_time)
      FROM fingerprint
      GROUP BY created_date

      Technology News @ www.JassimRahma.com

      J Offline
      J Offline
      Jassim Rahma
      wrote on last edited by
      #2

      Ok, Please HELLLLLP :confused: I have this table with 16 rows only: http://www.jassimrahma.com/temp/attendence_table.png[^] and I am using below code now to split the time of attendance into columns and getting this result: http://www.jassimrahma.com/temp/attendence_result.png[^] but I am not happoy with it! for example, 7th July, there is only one fingerprint so it should be only F1 but it's repeating it in F1, F3 and F4.

      SELECT DATE(attendance_date_time) AS attendance_date, SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(TIME(attendance_date_time)), ',', 1), ',', -1) AS F1,
      IF(LENGTH(GROUP_CONCAT(TIME(attendance_date_time))) - LENGTH(REPLACE(GROUP_CONCAT(TIME(attendance_date_time)), ',', '')) > 1,
      SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(TIME(attendance_date_time)), ',', 2), ',', -1) ,NULL) AS F2,
      SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(TIME(attendance_date_time)), ',', 3), ',', -1) AS F3,
      SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(TIME(attendance_date_time)), ',', 4), ',', -1) AS F4
      FROM employee_attendance
      GROUP BY DATE(attendance_date_time);

      How can I fix this please? Thanks, Jassim[^]

      Technology News @ www.JassimRahma.com

      J 1 Reply Last reply
      0
      • J Jassim Rahma

        Ok, Please HELLLLLP :confused: I have this table with 16 rows only: http://www.jassimrahma.com/temp/attendence_table.png[^] and I am using below code now to split the time of attendance into columns and getting this result: http://www.jassimrahma.com/temp/attendence_result.png[^] but I am not happoy with it! for example, 7th July, there is only one fingerprint so it should be only F1 but it's repeating it in F1, F3 and F4.

        SELECT DATE(attendance_date_time) AS attendance_date, SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(TIME(attendance_date_time)), ',', 1), ',', -1) AS F1,
        IF(LENGTH(GROUP_CONCAT(TIME(attendance_date_time))) - LENGTH(REPLACE(GROUP_CONCAT(TIME(attendance_date_time)), ',', '')) > 1,
        SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(TIME(attendance_date_time)), ',', 2), ',', -1) ,NULL) AS F2,
        SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(TIME(attendance_date_time)), ',', 3), ',', -1) AS F3,
        SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(TIME(attendance_date_time)), ',', 4), ',', -1) AS F4
        FROM employee_attendance
        GROUP BY DATE(attendance_date_time);

        How can I fix this please? Thanks, Jassim[^]

        Technology News @ www.JassimRahma.com

        J Offline
        J Offline
        Jassim Rahma
        wrote on last edited by
        #3

        anybody can help please?

        Technology News @ www.JassimRahma.com

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups