简体   繁体   English

Append 一个字符串值到哪里(从表中选择不同的字段)

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

I would like to append a string value onto an in clause.我想将 append 字符串值放到in子句中。 Eg this query retruns a field of string values:例如,此查询返回一个字符串值字段:

with

lut as (
select *
from mytable
)

select distinct "primary goal" from lut

I can also do this:我也可以这样做:

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

This returns the original data from the first select plus an additional row with value 'trial'.这将返回第一个 select 的原始数据加上一个值为“trial”的附加行。

I want to use this within a where in clause我想在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'))

Returns error:返回错误:

ERROR: Query unsupported due to an internal error.错误:由于内部错误,查询不受支持。 Detail: Unsupported query.详细信息:不支持的查询。 Where: Oid: 1101.其中:Oid:1101。

Adding the constant trail directly to the column, wound change nothing for the distinct, so ou would get the wanted result将常量轨迹直接添加到列中,伤口不会改变不同的东西,所以你会得到想要的结果

with

lut as (
select *
from mytable
)

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

IN Clause seems not fully be implemented IN 条款似乎没有完全实施

use JOIN使用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.

相关问题 如何从值为字典的表中获取 select 值,字典的键是使用 SQL 查询的数字? - How to select value from a table where value is a dictionary, and the key of the dictionary is a number using SQL query? 从 BigQuery 上的字符串字段获取结构化值 - Get a structured value from string field on BigQuery Flutter Firebase 遍历匹配字段值的所有文档,并将每个文档的字段插入字符串列表 - Flutter Firebase Iterate through all documents that matches field value and inserting field from each one into a List of String SQL 从两个表中计数(不同) - SQL count(distinct) from both the table 使用字符串从 Select - Using String to Select From 执行错误 SELECT * FROM "migrations_state" WHERE "key" =?: No value specified for parameter 1. db-migrate - Error executing SELECT * FROM "migrations_state" WHERE "key" = ?: No value specified for parameter 1. db-migrate 替代 select 在 firestore flutter 中不同 - Alternative to select distinct in firestore flutter 如何从变量表名中获取 select? - How to select from variable table name? 从超级字段中提取值 - Extract value from a super field Firebase 搜索不同字段时从一个字段获取值 - Firebase get value from one field when searching for different field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM