在不更新任何表的情况下将临时逗号添加到列中

时间:2019-04-01 07:33:49

标签: mysql sql

我有两个表并使用了一个简单的查询:

SELECT * FROM innerb where not exists 
   (select * from wms where barcode = innerb.barcode) and pcode like '%102';

我的结果是这样的:

enter image description here

我需要为所有值添加一个逗号,使其看起来像这样:

enter image description here

但是我不想更新表或创建新表,只是想添加几秒钟。

有什么想法吗?

2 个答案:

答案 0 :(得分:2)

您可以创建一个视图:

CREATE VIEW innerb_comma AS
SELECT CONCAT(Pcode, ',') AS Pcode,
       CONCAT(Brand, ',') AS Brand,
       CONCAT(Pdescription, ',') AS Pdescription,
       CONCAT(Size, ',') AS Size,
       CONCAT(Barcode, ',') AS Barcode
FROM innerb
WHERE NOT EXISTS (SELECT * FROM wms WHERE barcode = innerb.barcode) 
  AND Pcode like '%102';

然后从中进行选择:

SELECT * FROM innerb_comma

Demo on dbfiddle

答案 1 :(得分:0)

SELECT pcode || ',' as pcode
     , brand || ',' as brand
  FROM table

编辑:仅适用于某些DB。显然不是MYSQL(除非您将其配置为工作)。 What does SQL Select symbol || mean?列出了适用于哪个数据库的列表