有一种方法可以将选择结果用于同一个选择吗?
这样的东西?
选择10作为数字,(数字/ 2)作为一半FROM表
泰
EDIT //////////
好的,这是真正的交易。
SELECT * FROM (SELECT
(SUM(
CASE
WHEN JVB0 = 1 AND JHIT0 = 0 AND JER0 = ' ' THEN '1'
WHEN JVB0 = 1 AND JHIT0 = 0 AND JER0 = '' THEN '1'
WHEN JVB0 = 1 AND JSF0 = 1 AND JSH0 = 1 THEN '1'
ELSE 0
END)+
SUM(CASE
WHEN JDP0 = 1 OR JDP0 = 2 THEN '2'
WHEN JDP0 = 3 OR JDP0 = 4 THEN '3'
WHEN JOR0 = 1 THEN '1'
WHEN JACTB0 != '' THEN '1'
ELSE 0
END)) as tercios_thrown,
我必须把tercios_thrown的结果和一个使用tercios_thrown作为主号码的公式。所以我认为,如果不这样做可能是另一种方式:
SELECT * FROM (SELECT
(SUM(
CASE
WHEN JVB0 = 1 AND JHIT0 = 0 AND JER0 = ' ' THEN '1'
WHEN JVB0 = 1 AND JHIT0 = 0 AND JER0 = '' THEN '1'
WHEN JVB0 = 1 AND JSF0 = 1 AND JSH0 = 1 THEN '1'
ELSE 0
END)+
SUM(CASE
WHEN JDP0 = 1 OR JDP0 = 2 THEN '2'
WHEN JDP0 = 3 OR JDP0 = 4 THEN '3'
WHEN JOR0 = 1 THEN '1'
WHEN JACTB0 != '' THEN '1'
ELSE 0
END)) as tercios_thrown,
((SUM(
CASE
WHEN JVB0 = 1 AND JHIT0 = 0 AND JER0 = ' ' THEN '1'
WHEN JVB0 = 1 AND JHIT0 = 0 AND JER0 = '' THEN '1'
WHEN JVB0 = 1 AND JSF0 = 1 AND JSH0 = 1 THEN '1'
ELSE 0
END)+
SUM(CASE
WHEN JDP0 = 1 OR JDP0 = 2 THEN '2'
WHEN JDP0 = 3 OR JDP0 = 4 THEN '3'
WHEN JOR0 = 1 THEN '1'
WHEN JACTB0 != '' THEN '1'
ELSE 0
END)) / 3) as the_other_value
答案 0 :(得分:-1)
不允许在WHERE子句[或SELECT子句]中引用列别名,因为在执行子句时可能尚未确定列值。
所以不,你不能。