我有2张桌子
Table 1:
DB1, DB2, DB3, DB4, DB5, Some other identifiers
Table 2:
EnumText, EnumValue, Some other identifiers
我想做的是:-
- 从表1中选择数据
- 在选择期间,使用表 2 的 EnumText 列中的数据更改列 DB1 到 DB5 的别名,其中 EnumValue 将包含 DB1 到 DB5。
示例命令是:
Select
DB1 as [Select EnumText from Table2 where EnumValue='DB1'],
DB2, DB3
from Table1
这个命令不起作用,但我希望你们能明白。
先感谢您。
没有动态 SQL,就不可能有动态别名。如果您确实更改了结果集列名称,如何通过名称访问它们? (我不会使用索引,因为它会破坏)
所以,你可以添加一个固定列来描述它。并阅读that
Select
DB1, foo.EnumText AS DB1EnumText,
DB2,
DB3
from
Table1
CROSS JOIN
(Select EnumText from Table2 where EnumValue='DB1') foo
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)