SELECT device.id, device.device_name, if( deviceModel.device_model_name like "%双%" , 2 ) as num FROM t_bas_device device INNER JOIN t_bas_device_business_information deviceInfo ON device.id = deviceInfo.device_id INNER JOIN t_bas_device_type deviceSubType ON deviceSubType.id = device.device_sub_type_id INNER JOIN t_bas_device_model deviceModel on deviceModel.id = device.device_model_id WHERE deviceInfo.zone_id = "3b4ba520-a58b-e6c5-4018-70afcd390675" AND deviceSubType.device_type_code = "drainagePump" GROUP BY device.id ORDER BY device.sort ASC -- 如何根据 deviceModel.device_model_name 展示不同数据
时间: 2024-01-27 08:02:35 浏览: 101
可以使用 CASE WHEN 语句根据 deviceModel.device_model_name 展示不同数据,如下所示:
```
SELECT
device.id,
device.device_name,
CASE
WHEN deviceModel.device_model_name LIKE "%双%" THEN 2
ELSE 1
END AS num
FROM
t_bas_device device
INNER JOIN t_bas_device_business_information deviceInfo ON device.id = deviceInfo.device_id
INNER JOIN t_bas_device_type deviceSubType ON deviceSubType.id = device.device_sub_type_id
INNER JOIN t_bas_device_model deviceModel ON deviceModel.id = device.device_model_id
WHERE
deviceInfo.zone_id = "3b4ba520-a58b-e6c5-4018-70afcd390675"
AND deviceSubType.device_type_code = "drainagePump"
GROUP BY
device.id
ORDER BY
device.sort ASC;
```
这里使用了 CASE WHEN 语句来判断 deviceModel.device_model_name 是否包含 "双" 字符串,如果包含,则 num 为 2,否则为 1。
阅读全文