Why can't I use column aliases in the next SELECT expression?

前端 未结 4 826
别跟我提以往
别跟我提以往 2020-11-28 16:18

Can I modify the next to use the column aliases avg_time and cnt in an expression ROUND(avg_time * cnt, 2)?

SELECT 
           


        
4条回答
  •  爱一瞬间的悲伤
    2020-11-28 16:34

    Either repeat the expressions:

    ROUND(ROUND(AVG(time), 2) * COUNT(path), 2) as slowdown
    

    or use an subquery:

    SELECT *, ROUND(avg_time * cnt, 2) as slowdown FROM (
      SELECT 
        COALESCE(ROUND(stddev_samp(time), 2), 0) as stddev_time, 
        MAX(time) as max_time, 
        ROUND(AVG(time), 2) as avg_time, 
        MIN(time) as min_time, 
        COUNT(path) as cnt, 
        path
      FROM loadtime
      GROUP BY path) x
    ORDER BY avg_time DESC
    LIMIT 10;
    

提交回复
热议问题