我有一张桌子“第一”:
我正在尝试编写查询。
If first.type = 'MM'
then replace this line in two new lines
where first.type = 'HH' and first.type = 'VV'.
例如:first.type ='MM'的行:
我想像这样替换这一行:
结果:
有人知道如何做到这一点吗?
我正在使用MS SQL Server Management Studio Express。
答案 0 :(得分:3)
select id,freq,parity,line,type,gain,obdim from [first] where type<>'MM'
union
select id,freq,parity,line,'HH' as type,gain,obdim from [first] where type='MM'
union
select id,freq,parity,line,'VV' as type,gain,obdim from [first] where type='MM'
答案 1 :(得分:1)
select id,frequency, 'VV' type --, ..
from table1
where type='MM'
union all
select id,frequency, 'HH' as type --, ..
from table1
where type='MM'
答案 2 :(得分:1)
此解决方案可能非常具体,因为它意味着type
列只能包含值HH
,MM
或VV
。
SELECT
f.ID,
f.freq,
f.parity,
f.line,
t.type,
f.gain,
f.obdim
FROM [first] f
INNER JOIN (
SELECT 'HH' AS type
UNION ALL
SELECT 'VV'
) t ON f.type IN (t.type, 'MM')