MySql:填充列感谢IF条件?(参见里面的例子;))



我有一个数据库表,看起来像这样:

Ref1020050250

您需要条件聚合:

SELECT Name, Town,
MAX(CASE WHEN Type = 'Big' AND Brand = 'Sony' THEN Ref END) Big_Sony,
MAX(CASE WHEN Type = 'Big' AND Brand = 'Nokia' THEN Ref END) Big_Nokia,
MAX(CASE WHEN Type = 'Little' AND Brand = 'Sony' THEN Ref END) Little_Sony,
MAX(CASE WHEN Type = 'Little' AND Brand = 'Nokia' THEN Ref END) Little_Nokia
FROM tablename
GROUP BY Name, Town 

Results:
<表类>名称城镇Big_SonyBig_NokiaLittle_SonyLittle_Nokiatbody><<tr>卡洛斯里约热内卢空50空空弗朗索瓦•<<tr>/td>巴黎空空250空史密斯伦敦1020空空空

相关内容

  • 没有找到相关文章

最新更新