MySQL case语句错误,部分查询数据未显示
MySQL案例语句错误: 当我将以下内容作为单独的案例使用时,查询是有效的,但是当组合使用时,它们就不起作用了 我正在使用MySQL工作台 错误:MySQL case语句错误,部分查询数据未显示,mysql,Mysql,MySQL案例语句错误: 当我将以下内容作为单独的案例使用时,查询是有效的,但是当组合使用时,它们就不起作用了 我正在使用MySQL工作台 错误: 仅返回制造商信息,不返回基于ProdID的查询。 ProdID是正确的,在此之前我使用它来提取ID,它返回正确的ID 我要求他们在1列中运行下一步的计算 不工作: CASE When(T4.manufacturers_id = 1) then '' When(T4.manufacturers_id = 2) then '.10'
仅返回制造商信息,不返回基于ProdID的查询。
ProdID是正确的,在此之前我使用它来提取ID,它返回正确的ID 我要求他们在1列中运行下一步的计算 不工作:
CASE
When(T4.manufacturers_id = 1) then ''
When(T4.manufacturers_id = 2) then '.10'
When(T4.manufacturers_id = 3) then '.10'
When(T4.manufacturers_id = 4) then '0'
When(T3.products_id = 11) then '.10'
When(T3.products_id = 34) then '.10'
When(T3.products_id = 35) then '.10'
When(T3.products_id = 36) then '.10'
When(T3.products_id = 37) then '.10'
When(T3.products_id = 38) then '.10'
When(T3.products_id = 39) then '.10'
end As Comms,
工作:
CASE
When(T4.manufacturers_id = 1) then ''
When(T4.manufacturers_id = 2) then '.10'
When(T4.manufacturers_id = 3) then '.10'
When(T4.manufacturers_id = 4) then '0'
end As MIDComms,
case
When(T3.products_id = 11) then '.10'
When(T3.products_id = 34) then '.10'
When(T3.products_id = 35) then '.10'
When(T3.products_id = 36) then '.10'
When(T3.products_id = 37) then '.10'
When(T3.products_id = 38) then '.10'
When(T3.products_id = 39) then '.10'
end As PIDComms,
CASE
When(T4.manufacturers_id = 1) then ''
When(T4.manufacturers_id = 2) then '.10'
When(T4.manufacturers_id = 3) then '.10'
When(T4.manufacturers_id = 4) then '0'
When(T3.products_id = 11) then '.10'
When(T3.products_id) between 34 and 39 then '.10'
end As Comms,
理想情况下,我希望它是:
CASE
When(T4.manufacturers_id = 1) then ''
When(T4.manufacturers_id = 2) then '.10'
When(T4.manufacturers_id = 3) then '.10'
When(T4.manufacturers_id = 4) then '0'
end As MIDComms,
case
When(T3.products_id = 11) then '.10'
When(T3.products_id = 34) then '.10'
When(T3.products_id = 35) then '.10'
When(T3.products_id = 36) then '.10'
When(T3.products_id = 37) then '.10'
When(T3.products_id = 38) then '.10'
When(T3.products_id = 39) then '.10'
end As PIDComms,
CASE
When(T4.manufacturers_id = 1) then ''
When(T4.manufacturers_id = 2) then '.10'
When(T4.manufacturers_id = 3) then '.10'
When(T4.manufacturers_id = 4) then '0'
When(T3.products_id = 11) then '.10'
When(T3.products_id) between 34 and 39 then '.10'
end As Comms,
提前感谢一个
case
语句只返回一个值,即遇到的第一个值。也许您需要某种连接:
CONCAT_WS(':',
(CASE When(T4.manufacturers_id = 1) then ''
When(T4.manufacturers_id = 2) then '.10'
When(T4.manufacturers_id = 3) then '.10'
When(T4.manufacturers_id = 4) then '0'
END),
(CASE When(T3.products_id = 11) then '.10'
When(T3.products_id = 34) then '.10'
When(T3.products_id = 35) then '.10'
When(T3.products_id = 36) then '.10'
When(T3.products_id = 37) then '.10'
When(T3.products_id = 38) then '.10'
When(T3.products_id = 39) then '.10'
end) ) As Comms,
非常感谢,我知道这将是一件简单的事情,我只是不知道该怎么办:)太好了。