我有一个select语句,根据不同的标准显示多个计数
我想将计数传递给用户定义的函数(UDF)来进行一些计算
e.g。
SELECT
player,
COUNT(IF(action=1,1,NULL)) AS tot_bullseye,
COUNT(IF(action=2,1,NULL)) AS tot_twentys
UDF(tot_bullseye, tot_twentys)
答案 0 :(得分:1)
不,对于同一查询,永远不能在SELECT
或WHERE
子句中访问列别名。您必须重复表达式,或使用子查询:
SELECT player, tot_bullseye, tot_twentys, UDF(tot_bullseye, tot_twentys)
FROM (SELECT player,
COUNT(IF(action=1,1,NULL)) AS tot_bullseye,
COUNT(IF(action=2,1,NULL)) AS tot_twentys
...) AS subq