MySQL - How to display row value as column name using concat and group_concat

后端 未结 3 1066
无人共我
无人共我 2020-12-06 23:14

Table 1:

id   | typeid | available|
0    | 1      | 12       |
0    | 2      | 44       |

Table 2:

<
3条回答
  •  失恋的感觉
    2020-12-06 23:17

    Try this:

    SELECT a.id, MAX(IF(b.typename = 'CL', a.available, 0)) CL, 
           MAX(IF(b.typename = 'ML', a.available, 0)) ML
    FROM table1 a
    INNER JOIN table2 b ON a.typeid=b.typeid
    GROUP BY a.id;
    

    Use SUM function if you want to sum of the data from available column for particualr type else use the same query as ii is.

提交回复
热议问题