mysql别名的未知列问题 [英] Unknown column issue with mysql alias
本文介绍了mysql别名的未知列问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当列是已创建的别名时,我不知道为什么会得到未知列.任何帮助都会很棒.
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.
代码:
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 (width BETWEEN '0' AND '275')
AND (height BETWEEN '0' AND '599')
ORDER BY c.item_no
错误:
"where子句"中的未知列"width"
Unknown column 'width' in 'where clause'
推荐答案
您不能直接通过名称访问别名.
You cannot access the alias directly by name.
一种解决方案是将带有别名的查询包装在子查询中,然后在外部查询中引用别名:
One solution is to wrap the query with the aliases in a subquery, and then refer to the alias names in an outer query:
SELECT DISTINCT *
FROM
(
SELECT 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'
) sub
WHERE (sub.width BETWEEN '0' AND '275')
AND (sub.height BETWEEN '0' AND '599')
ORDER BY sub.item_no
这篇关于mysql别名的未知列问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文