我有这个T-SQL(简化):
select 3.00 as score1, null as score2, null as score3, null as score4
union all
select null as score1, 4.5 as score2, 1.5 as score3, null as score4
生产:
score1 score2 score3 score4
------------------------------
3.00 NULL NULL NULL
NULL 4.5 1.5 NULL
但是,我还是要加入其中一行:
score1 score2 score3 score4
------------------------------
3.00 4.5 1.5 NULL
Sorry - impping blank(it晚)。
是否需要临时表格?
这样做的原因是,我有以下联系:
Reviews 1.* Scores
因此,如果你知道:
INSERT INTO OtherTable (ReviewId, Score1, Score2, Score3, Score4)
????
希望是有意义的。
http://www.ohchr.org。
基于@OMG 回答(他刚刚去除),即:
SELECT CASE MAX(x.score1) WHEN 0 THEN NULL ELSE MAX(x.score1) END AS score4
CASE MAX(x.score2) WHEN 0 THEN NULL ELSE MAX(x.score2) END AS score4
CASE MAX(x.score3) WHEN 0 THEN NULL ELSE MAX(x.score3) END AS score4
CASE MAX(x.score4) WHEN 0 THEN NULL ELSE MAX(x.score4) END AS score4
FROM (select 3.00 as score1, 0 as score2, 0 as score3, 0 as score4
union all
select 0 as score1, 4.5 as score2, 1.5 as score3, 0 as score4) x
但这只是粗略的。 任何其他想法?