我如何在SQL查询中设置标志

时间:2016-09-19 10:17:37

标签: mysql sql

我的查询:

CREATE OR REPLACE VIEW Basic
AS
SELECT id FROM my_post
UNION
SELECT id FROM scrap_post

如果该行来自my_post,那么我想设置标记p,否则设置s

1 个答案:

答案 0 :(得分:3)

添加硬编码值

CREATE OR REPLACE VIEW Basic
AS
select id,'p' as flag from my_post
UNION 
select id,'s' from scrap_post

注意:如果您不关心结果中的重复项,请将UNION更改为运行速度更快的UNION ALL