Unknown column issue with mysql alias

后端 未结 3 766
走了就别回头了
走了就别回头了 2021-01-12 06:03

I can\'t figure out why i am getting an unknown column when the column is an alias that was created. Any help would be great.

code:

SELECT DISTINCT 
         


        
3条回答
  •  长发绾君心
    2021-01-12 06:49

    I don't think you can use your "width" alias in your "width between .. and .."; you need to repeat the raw calculation, sadly. Same for "height". So, the following should work:

    SELECT   DISTINCT c.id, 
             ((SUM(c.width_feet)*12)+(SUM(c.width_inches))) AS width, 
             ((SUM(c.height_feet)*12)+(SUM(c.height_inches))) AS height 
    FROM     carpets AS c 
    WHERE    c.active = '1' 
    AND      (((SUM(c.width_feet)*12)+(SUM(c.width_inches))) BETWEEN '0' AND '275') 
    AND      (((SUM(c.height_feet)*12)+(SUM(c.height_inches))) BETWEEN '0' AND '599') 
    ORDER BY c.item_no 
    

提交回复
热议问题