GQS
GQS

Reputation: 129

How to concatenate 2 values based on the value of a different column in mysql?

I have this MySQL table:

TagName, Temp Type, DateTime, Value
'SGTC.0014', '_Top_Temp', '2022-07-05 18:48:17', 'Top=103.0'
'SGTC.0014', '_Bot_Temp', '2022-07-05 18:48:17', 'Bot=-16.3'
'SGTC.0013', '_Bot_Temp', '2022-07-05 18:48:17', 'Bot=107.7'
'SGTC.0013', '_Top_Temp', '2022-07-05 18:48:16', 'Top=5.9'

I want to concatenate the values in Value to a new table to make it like this based on the same timing and top and bot values:

TagName, DateTime, Value
'SGTC.0014','2022-07-05 18:48:17', 'Top=103.0,Bot=-16.3'

I am stuck with concatenating the values as I am not sure how to do it. Any help is appreciated thanks!

Upvotes: 1

Views: 29

Answers (1)

DRapp
DRapp

Reputation: 48139

You need to read up on Group_Concat

select
      yt.TagName,
      yt.DateTime,
      group_concat( yt.Value ) TopAndBottomValues
   from
      YourTable yt
   group by
      yt.TagName,
      yt.DateTime

Upvotes: 1

Related Questions