我有这样的桌子 % U5 O' O0 Q, Y7 b5 [, r8 rID | Type | Val0 | Val1' O# X5 l2 W, `2 f# r
1 | 0 | A | NULL ! S( C# U, a) X" W! f2 | 1 | NULL | B " W0 n7 U4 Q* ?- s0 h我需要选择Val0何时类型为0,Val1何时类型为1,ValN何时类型为N …4 z0 g% N3 ?# s( }, H# t" m, U
我怎样才能做到这一点? " ~+ K2 _6 o1 f' e1 c+ ? # @9 U$ Y, S3 e" i- k4 W 解决方案:# H. u" @; z r; Y# h
$ X& ~% {# V$ s; h3 t8 W
5 t- o2 ` e- m0 _& f; \# `3 D' u3 o ! f/ s3 q2 `4 i1 O SELECT CASE% q/ ?: N/ r' g! n" ]# m4 X
WHEN Type = 0 THEN Val0 7 R. _* a1 y, w. S! \+ A WHEN Type = 1 Then Val17 p) ~1 C n2 C( O) Z
. , T8 I! r' H$ h . 8 h4 ]5 z$ O+ v& }/ u WHEN Type = N Then ValN 8 ~6 q7 h$ F* V END ( V$ A! n# J" O' J2 v FROM tbl