SQL:如何用两个替换一个?
问题描述:
我有一个表 “第一”:SQL:如何用两个替换一个?
我想编写一个查询。
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。
答
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'
答
select id,frequency, 'VV' type --, ..
from table1
where type='MM'
union all
select id,frequency, 'HH' as type --, ..
from table1
where type='MM'
答
这种解决方案可能是在这个意义上非常特殊,它意味着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')
+1,但请将*扩展到实际列中。这张桌子得到更新后不久,所有东西都分崩离析。 – Dane 2011-04-11 06:59:32
谢谢。这解决了我的问题。 – Juronis 2011-04-12 06:57:12