选择从查询中检索列名的列 [英] select a column where the column name is retrieved from a query

查看:91
本文介绍了选择从查询中检索列名的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种从表A中选择列的优雅方法,该列的名称是从对表B的查询中检索到的.

I'm looking for a elegant way to select a column from table A where as the column name is retrieved from a query on table B.

对表B的查询导致'col01' 表A中有几列名为'col01','col02','col03',...

A query on table B results in 'col01' The Table A has several columns named 'col01','col02','col03',...

最终查询应针对结果


result from B | effective SQL query
 'col01'      |  SELECT col01 FROM A
 'col02'      |  SELECT col02 FROM A

我正在寻找没有脚本的纯SQL解决方案.它应与Oracle和/或MySQL一起运行.

I'm looking for pure SQL solution with no scripting. It should run with Oracle and/or MySQL.

推荐答案

我正在寻找没有脚本的纯SQL解决方案.

I'm looking for pure SQL solution with no scripting.

这是不可能的.您必须动态创建语句.

This is not possible. You have to create the statements dynamically.

这篇关于选择从查询中检索列名的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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