Pivot Tables PHP/MySQL

前端 未结 1 570
半阙折子戏
半阙折子戏 2020-12-05 22:32

What\'s the best way of handling pivot tables in php/MySQL (or something to that effect)

I have a query that returns information as below

id      eng         


        
相关标签:
1条回答
  • 2020-12-05 23:24

    You can likely do this with a sub-query and then produce and aggregation of this data. Try something along the lines of this:

    select week, 
        count(*) as total, 
        sum(technical) as technical, 
        sum(non_technical) as non_technical) 
    from(
        select week, 
        case(type) when 'Technical' then 1 else 0 END as technical, 
        case(type) when 'Non-Technical' then 1 else 0 END as non_technical
    ) as data
    GROUP BY week
    
    0 讨论(0)
提交回复
热议问题