需求:库存上报有些为负数,需显示为0
解决:用SELECT CASE WHEN a(字段名)< 0 THEN 0 ELSE a END a
表数据:
SELECT
ID,
EQUIP_NO,
EQUIP_NAME,
STORAGE_NO,
DRUG_ID,
DRUG_NAME,
CURRENT_HEIGHT,
STATUS,
CASE WHEN QUANTITY < 0 THEN 0 ELSE QUANTITY END QUANTITY,
PALLET_TYPE,
INDEX_NO,
VALID_DATE,
LOT_NO
FROM eq_equipment_storage_drugs
WHERE 1 = 1
执行sql运行结果为