全部产品
阿里云办公

HAVING语句

更新时间:2018-09-29 17:51:28

HAVING 子句

您需要添加HAVING子句,才能使WHERE语句和合计函数一起运用。

语法

  1. SELECT [ ALL | DISTINCT ]{ * | projectItem [, projectItem ]* }
  2. FROM tableExpression
  3. [ WHERE booleanExpression ]
  4. [ GROUP BY { groupItem [, groupItem ]* } ]
  5. [ HAVING booleanExpression ];

示例

测试数据

Customer OrderPrice
Bush 1000
Carter 1600
Bush 700
Bush 300
Adams 2000
Carter 100

测试语句

  1. SELECT Customer,SUM(OrderPrice) FROM XXX
  2. GROUP BY Customer
  3. HAVING SUM(OrderPrice)<2000;

测试结果

Customer SUM(OrderPrice)
Carter 1700