如何在PostgreSQL ORDER BY子句中使用ALIAS?
发布时间:2020-12-13 16:06:46 所属栏目:百科 来源:网络整理
导读:我有以下查询: select title,( stock_one + stock_two ) as global_stockfrom productorder by global_stock = 0,title; 在PostgreSQL 8.1.23中运行它我收到此错误: 查询失败:错误:列“global_stock”不存在 有人可以帮我把它投入使用吗?我首先需要可用
我有以下查询:
select title,( stock_one + stock_two ) as global_stock from product order by global_stock = 0,title; 在PostgreSQL 8.1.23中运行它我收到此错误: 查询失败:错误:列“global_stock”不存在 有人可以帮我把它投入使用吗?我首先需要可用的项目,然后是不可用的项目.非常感谢! 解决方法
您可以随时以这种方式订购:
select title,( stock_one + stock_two ) as global_stock from product order by 2,1 或将其包装在另一个SELECT中: SELECT * from ( select title,( stock_one + stock_two ) as global_stock from product ) x order by (case when global_stock = 0 then 1 else 0 end) desc,title (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |