Text values in a pivot table?

后端 未结 3 1366
悲哀的现实
悲哀的现实 2020-12-20 00:41

I have a table (in MySQL) with 3 columns:

Location    Category     Supplier

   A        Computers    Company X
   A        Printers     Company Y
   B               


        
3条回答
  •  一生所求
    2020-12-20 01:23

    I have no way to check if the query is fine, but more or less would be a query like this:

    SELECT t1.Location, MAX(t1.Computers), MAX(t1.Printers),  MAX(t1.Software)
    
    FROM (
    SELECT
     t.Location,
     CASE WHEN t.Category = 'Computers' THEN
       t.Supplier
     END Computers,
    
     CASE WHEN t.Category = 'Printers' THEN
       t.Supplier
     END Printers,
    
     CASE WHEN t.Category = 'Software' THEN
       t.Supplier
     END Software,
    FROM
    YOUR_TABLE t
    ) t1
    GROUP BY t1.Location
    

提交回复
热议问题