Reputation: 4151
I have a certain result-set and I need to group them together on userId.
e.g.
userId 2019-01-15 2019-01-16
------------------------------
132 0 30_140
132 30_140 0
Required output:
userId 2019-01-15 2019-01-16
------------------------------
132 30_140 30_140
Since values contain non-numeric characters, SUM won't work.
Upvotes: 1
Views: 374
Reputation: 147256
If the empty values are all 0
or NULL
you can just use MAX
:
SELECT userID, MAX(`2019-01-15`) AS `2019-01-15`, MAX(`2019-01-16`) AS `2019-01-16`
FROM test
GROUP BY userID
Output:
userID 2019-01-15 2019-01-16
132 30_140 30_140
Upvotes: 4