我有一个有效的查询,该查询会拉回与特定“站点”相关的“商店”。一些商店与多个站点相关。
**602 = site1**
store 602
store2 602
store3 602
在我的查询中是否有一种方法可以用“ site1”标记602,使其看起来像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
提前谢谢
答案 0 :(得分:1)
使用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