簡體   English   中英

Append 一個字符串值到哪里(從表中選擇不同的字段)

[英]Append a string value to where in (select distinct field from table)

我想將 append 字符串值放到in子句中。 例如,此查詢返回一個字符串值字段:

with

lut as (
select *
from mytable
)

select distinct "primary goal" from lut

我也可以這樣做:

select distinct "primary goal" from lut union all (select 'trial')

這將返回第一個 select 的原始數據加上一個值為“trial”的附加行。

我想在where in子句中使用它

with

lut as (
select *
from mytable
)

select *
from anothertable
where event_name in (select distinct "primary goal" from lut union all (select 'trial'))

返回錯誤:

錯誤:由於內部錯誤,查詢不受支持。 詳細信息:不支持的查詢。 其中:Oid:1101。

將常量軌跡直接添加到列中,傷口不會改變不同的東西,所以你會得到想要的結果

with

lut as (
select *
from mytable
)

select distinct CONCAT('trial',"primary goal") from lut

IN 條款似乎沒有完全實施

使用JOIN

with

lut as (
select *
from mytable
)

select *
from anothertable a JOIN (select distinct "primary goal" as lut_name from lut union all (select 'trial')) t1
ON a.event_name = t1.lut_name

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM