0

我有一个存储位置值的数据表,如下所示:CTY_CD、STATE_CD、COUNTRY_CD 并且我想在给定城市代码的情况下从该表中进行选择,并选择所有三个位置代码作为单独的行,另一列显示它是什么 loc 类型,所以结果的查询看起来像:

Given city code DEN:

Type         |    Code
CTY_CD            DEN
STATE_CD          CO
COUNTRY_CD        US

有没有办法做到这一点?

4

1 回答 1

1

像这样的东西?

 select 'CTY_CD' AS Type,  CTY_CD AS Code FROM tableName WHERE CTY_CD = 'DEN'
 UNION
 select 'STATE_CD' AS Type, STATE_CD AS Code FROM tableName WHERE CTY_CD = 'DEN'
 UNION
 select 'COUNTRY_CD' AS Type, COUNTRY_CD AS Code FROM tableName WHERE CTY_CD = 'DEN'
于 2012-06-26T14:46:19.780 回答