更改sql搜索结果中的值

kokeuurv  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(337)

我有一个有效的查询,它可以收回与特定“站点”相关的“商店”。有些商店与多个地点有关。


**602 = site1**

store   602
store2  602
store3  602

在我的查询中,是否有一种方法将602标记为“site1”,使其看起来像602(site1)。所以它会显示:

store   602(site1)
store2  602(site1)
store3  602(site1)

我的问题如下:

SELECT BS.PK, BS.p_uid, O.p_salesoffice, Count(O.Code)
FROM orders AS O
JOIN basestore AS BS ON O.p_store = BS.PK
WHERE (BS.PK = '8796093056989' AND O.p_salesoffice IN (602, 177))
GROUP BY BS.p_uid, O.p_salesoffice

先谢谢你

im9ewurl

im9ewurl1#

使用 concat 正如你所说,你只需要602所以使用 case when ```
select PK,
p_uid,
case when p_salesoffice=602 then concat(p_salesoffice,' (site1)')
else p_salesoffice end as salesoffice,
Cnt
from
(
SELECT BS.PK as PK, BS.p_uid as p_uid, O.p_salesoffice as p_salesoffice, Count(O.Code) as Cnt
FROM orders AS O
JOIN basestore AS BS ON O.p_store = BS.PK
WHERE (BS.PK = '8796093056989' AND O.p_salesoffice IN (602, 177))
GROUP BY BS.p_uid, O.p_salesoffice
) as T

相关问题