Amazon Redshift:根据表中存在的列列表选择列 [英] Amazon Redshift: Selecting columns based on a list of columns present in a table

查看:80
本文介绍了Amazon Redshift:根据表中存在的列列表选择列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以以任何方式(无需编写脚本)聚合存储在表格单元格中的列.

Is it possible in any way (without scripting) to aggregate columns which are stored in a table cell.

基本上我要在这里实现的是,如果我有下表

Basically what i am trying to achieve here is that if i have the following table

Table 1
KEYNAME    | COLUMN_NAME
COUNT_USER | USER_ID
SUM_HOURS  | HOURS_WATCHED

我可以做类似的事情

select SUM((select column_name from TABLE1 where KEYNAME = "SUM_HOURS")) FROM MAIN_TABLE

我可以选择在python中编写脚本,我知道该如何实现.但是我很想知道在任何版本的SQL中这是否可行 请让我知道信息是否足够.

I have the option to script in python via which i know how to achieve this. But i am curious to know if this is possible in any version of SQL or not Please let me know if the information is insufficient.

推荐答案

否,您不能使用来自另一个查询结果的列名.

No, you cannot use a column name that comes from the result of another query.

您将需要使用自己的代码执行此操作,将结果作为完整查询发送到Amazon Redshift. (也就是说,运行一个查询以获取列名,然后运行第二个查询并插入这些列名.)

You would need to do this in your own code, sending the result to Amazon Redshift as a complete query. (That is, run one query to obtain the column names, then run a second query with those column names inserted.)

这篇关于Amazon Redshift:根据表中存在的列列表选择列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆