gpt4 book ai didi

sql - WHERE 强制转换列名等于

转载 作者:搜寻专家 更新时间:2023-10-30 20:00:16 25 4
gpt4 key购买 nike

是否可以编写一个 where 语句,使用已分配给列的列名而不是实际存在的列名?整个表是动态创建的,列名存储在另一个表中。我有一个功能,允许用户在检索随附的数据集之前向 jobect 添加过滤器。

我正在尝试的示例:

SELECT id, 
col1 as [description],
col2 as [date1],
col3 as [image],
col4 as [date2],
col5 as [link],
col6 as [location],
col7 as [price],
col8 as [title]
FROM tableName
WHERE [title] = 'Lemons'

最佳答案

使您的原始查询成为子查询:

SELECT *
FROM (
SELECT id,
col1 as [description],
col2 as [date1],
col3 as [image],
col4 as [date2],
col5 as [link],
col6 as [location],
col7 as [price],
col8 as [title]
FROM tableName
) as subquery
WHERE [title] = 'Lemons'

关于sql - WHERE 强制转换列名等于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6785786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com