我有这个表,我希望有一个select语句,根据给定的代码选择VALUE。 可能需要CASE语句,但到目前为止我查看的所有示例都有不同的值作为案例的结果。
表A
ID || VALUE
1 || value1
2 || value2
3 || value3
4 || value4
5 || value5
6 || value3
7 || value2
8 || value8
表B
ID ||CODE
1 ||1
2 ||2
3 ||3
4 ||4
5 ||1
6 ||2
7 ||3
8 ||4
SELECT B.CODE,
CASE
WHEN B.CODE = '01' THEN A.value based on code
WHEN B.CODE = '02' THEN A.value based on code
WHEN B.CODE = '03' THEN A.value based on code
WHEN B.CODE = '04' THEN A.value based on code
END AS VALUE_OUT
FROM A JOIN B
ON A.ID = B.ID;
答案 0 :(得分:1)
您可能只需要一个static
子句
WHERE
修改强>
看起来Select Value
From MyTable
Where Code = 1
就足够了:
INNER JOIN
答案 1 :(得分:0)
我想你只想
SELECT DISTINCT
code, value
FROM MyTable
或
SELECT DISTINCT
value
FROM MyTable
WHERE code = 1
如果您想要特定代码的所有值。