我尝试在postgres中使用别名来进行此查询,但postgres停止并抱怨ERROR:列“小计”不存在
SELECT SUM(price) AS subtotal,
subtotal * 3.0 AS fees,
(subtotal + fees) AS total
FROM cart
您不能将别名用作下一栏的一部分吗?
答案 0 :(得分:5)
不,您不能在同一SQL语句中重用列别名 - 使用:
SELECT SUM(t.price) AS subtotal,
SUM(t.price) * 3.0 AS fees,
SUM(t.price + fees) AS total
FROM CART t
您可以在ORDER BY子句中引用列别名,某些数据库还支持GROUP BY
和HAVING
子句中的引用。
答案 1 :(得分:0)
关于你的回答的问题:
SELECT SUM(t.price) AS subtotal,
SUM(t.price) * 3.0 AS fees,
SUM(t.price + (t.price * 3.0)) AS total
FROM CART t
如果您不能在同一SQL语句中重用列别名,那么它是否应该是以下内容:
$(".checkout-button").click(function(){
$.post(
"{% url 'book:booking' %}",
seat_total,
function (response) {
window.location.href = "{% url 'book:booking' %}"
}
);
});