MySql

mysql中一个字段根据另一字段的值分割为不同列

2022-03-08  本文已影响0人  星钻首席小管家
image.png
SELECT
    vehicle_id,IF (mileage_type = 1, mileage, 0) AS nonExcutionMileage,IF (mileage_type = 0, mileage, 0) AS excutionMileage
FROM
    gps_basis.having_opened_vehicle_mileage_detail
SELECT vehicle_id,date,
 case mileage_type when 0 then mileage else 0 end excutionMileage, 
 case mileage_type when 1 then mileage else 0 end nonExcutionMileage
FROM gps_basis.having_opened_vehicle_mileage_detail 
上一篇 下一篇

猜你喜欢

热点阅读