查询比9号用户订单总金额(订单金额列名是oamount)低的用户,列出用户id和订单总金额。语句是: SELECT uid AS order total FROM orders uid order total< (SELECT FROM orders WHERE uid=9);
时间: 2024-04-01 07:38:06 浏览: 62
这个SQL语句是错误的,应该是:
SELECT uid, SUM(oamount) AS order_total FROM orders WHERE uid <> 9 GROUP BY uid HAVING order_total < (SELECT SUM(oamount) FROM orders WHERE uid = 9);
这个语句的含义是首先查询uid不等于9的所有订单,计算每个用户的订单总金额;然后根据uid分组,筛选出订单总金额低于9号用户订单总金额的用户;最后显示这些用户的uid和订单总金额。
阅读全文