其中soundex是指「發言模糊搜索」,例:SELECT cust_name, cust_contact FROM customers WHERE Soundex(cust_contact) = 'Lie'; 能夠搜索出Lee的表列。mysql
日期和時間處理函數 sql
數值處理函數 函數
彙總數據
限定符DISTINCT限定列中不一樣的行 省略時默認值爲ALL,彙集函數能夠組合使用處理多個列查詢
AVG: SELECT AVG(prod_price) AS prod_avg FROM products WHERE prod_name = 'fish'; (AVG()函數忽略列值爲NULL的行)
COUNT: SELECT COUNT(*) AS pro_rowSum FROM products; 返回總行數,包括NULL。
MAX: SELECT MAX(prod_price) AS pro_expensive FROM products; 返回篩選條件列的最高價格;與此相反的有MIN函數
SUM: SELECT SUM(pro_price) AS pro_total FROM products WHERE pro_price > 200; 取和
分組數據
GROUP BY 和 HAVING: SELECT cust_id, COUNT(*) AS orders FROM orders GROUP BY cust_id HAVING * >= 2; HAVING 具備和WHERE相同的功能,可是具備分組特性。 ORDER BY 和 GROUP BY 一塊兒使用以及其區別
聯結表
經過主鍵與外鍵,將兩個表中具備的相關聯的鍵匹配查詢所須要的表結構: SELECT vend_name, prod_name, prod_price FROM vendors INNER JOIN products ON vendors.vend_id = products.prod_id ; (等價於) SELECT vend_name, prod_name, prod_price FROM vendors, products WHERE vendors.vend_id = products.prod_id ;
能夠使用AND聯結多個子句圖片
外鏈接(左鏈接和右鏈接): SELECT vend_name, prod_name, prod_price FROM vendors LEFT OUTER JOIN products ON vendors.vend_id = products.prod_id ; 和內鏈接相比,外鏈接以LEFT或RIGHT表爲主,對於沒有鏈接的行以NULL補充數據返回。