user1002870
user1002870

Reputation: 3

SQL Query group data

I have data as below.

     Group  Jan     Feb      Mar
---|------|-----|-------|--------|---------
   |   A  | I22 |       |        |
   |   A  |     | I22   |        |
   |   A  |     |       | I22    |
   |   B  | I33 |       |        |
   |   B  |     | I33   |        |
   |   B  |     |       | I33    |

How is the query to make the data like this:-

     Group  Jan     Feb      Mar
---|------|-----|-------|--------|---------
   |   A  | I22 | I22   |  I22   |
   |   B  | I33 | I33   |  I33   |

Upvotes: 0

Views: 135

Answers (1)

Joe Stefanelli
Joe Stefanelli

Reputation: 135739

Group is a keyword so you'll need to escape it appropriately for your RDBMS (e.g., square brackets for SQL Server, backticks for MySQL, etc).

SELECT [Group], MAX(Jan), MAX(Feb), MAX(Mar)
    FROM YourTable
    GROUP BY [Group]

Upvotes: 1

Related Questions