抛砖引玉了,SELECT count( num1 ) AS num1_count , num1 AS num1_value
FROM `site_contact_stat`
GROUP BY `num1`这样就能查出 字段num1的 信息,那么其他的也能写在一起吗?怎么写呢?

解决方案 »

  1.   

    这分我拿了,不给我分我和你急
    select sum(case n_1 when 1 then 1 else 0 end) as num1_1,
           sum(case n_1 when 2 then 1 else 0 end) as num1_2,
           sum(case n_1 when 0 then 1 else 0 end) as num1_0,       sum(case n_2 when 1 then 1 else 0 end) as num2_1,
           sum(case n_2 when 2 then 1 else 0 end) as num2_2,
           sum(case n_2 when 0 then 1 else 0 end) as num2_0,       sum(case n_3 when 1 then 1 else 0 end) as num3_1,
           sum(case n_3 when 2 then 1 else 0 end) as num3_2,
           sum(case n_3 when 0 then 1 else 0 end) as num3_0,       sum(case n_4 when 1 then 1 else 0 end) as num4_1,
           sum(case n_4 when 2 then 1 else 0 end) as num4_2,
           sum(case n_4 when 0 then 1 else 0 end) as num4_0
    from t_1
    result
    4 0 2 2 1 3 1 4 1 4 2 0