1. HAVING

在 SQL 中增加 HAVING 子句原因是,WHERE 关键字无法与合计函数一起使用

实例:现表Orders(订单)有如下字段:

   Id,Date,Price ,Customer

#查找订单总金额少于 2000 的客户。
SELECT Customer,SUM(Price) FROM Orders
GROUP BY Customer
HAVING SUM(Price)<2000;
#查找客户 "Bush" 或 "Adams" 拥有超过 1500 的订单总金额。(添加where子句)
SELECT Customer,SUM(Price) FROM Orders
WHERE Customer='Bush' OR Customer='Adams'
GROUP BY Customer
HAVING SUM(Price)>1500;

2. USING

Mysql 中联接SQL语句中,ON子句的语法格式为:table1.column_name = table2.column_name。

当模式设计对联接表的列采用了相同的命名样式时,就可以使用 USING 语法来简化 ON 语法,格式为:USING(column_name)。
 
实例:
SELECT * FROM table1 INNER JOIN table2 ON table1.id = table2.id;

等价于

SELECT * FROM table1 INNER JOIN table2 USING(id);

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-26
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-04
  • 2022-12-23
  • 2021-07-08
  • 2022-12-23
  • 2021-10-05
  • 2021-09-06
  • 2021-07-01
相关资源
相似解决方案