My Sql整理

63 阅读1分钟

查询语句执行顺序

MySQL 分组依据

以下我将会写一个添加了a lot使用语法的语句,用来检测自己是否还记得(没有逻辑在里面,只是为了包含语法):

SELECT DISTINCT 
  customername AS name,
  CONCAT_WS(', ', lastName, firstname) `Full name`, 
  country City, state, creditlimit,
  orderNumber `Order no.`, 
  SUM(priceEach * quantityOrdered) total
FROM customers m
RIGHT JOIN committees c USING(name)
WHERE 
  m.member_id IS NULL AND
  (country = 'USA' OR country = 'France') AND 
  state IN ('CA' , 'PA') AND 
  state NOT IN('DA') AND
  creditlimit > 100000 AND
  productCode LIKE '%\_20%' AND
  requireddate BETWEEN 
    CAST('2003-01-01' AS DATE) AND 
    CAST('2003-01-31' AS DATE)
ORDER BY filed(c,'job','life','cook')`
LIMIT 20, 10
GROUP BY
	`Order no.`
HAVING
	total > 60000;