USING
用於表連接時給定連接條件(可以理解為簡寫形式),如
SELECT * FROM table1 JOIN table2 ON table1.id = table2.id
使用 USING 可以寫為
SELECT * FROM table1 JOIN table2 USING(id)
就這么簡單
HAVING
引入 HAVING 是因為 WHERE 無法和統計函數一起使用
如表 order (定單)有如下字段:
id, date, price, customer
查找訂單總額少於2000的客戶可以這樣寫:
SELECT customer, SUM(price) FROM order GROUP BY customer HAVING SUM(price)<2000
查找指定客戶中訂單超過1500的訂單總額:
SELECT customer,SUM(price) FROM order WHERE customer=’…’ OR customer = ‘…’ GROUP BY customer HAVING SUM(price) > 1500
mysql的一些用法:
得到文件路徑的文件名:類似basename()
substring_index(`fullpath`, '/', -1) as filename