MySQL之SQL語法例項大全:1-10
阿新 • • 發佈:2019-01-23
1.從table中讀取某一Column(例如:dept_name)
程式碼:
select dept_name from departments;
結果:
2.從table中讀取全部Column
程式碼:
select * from departments
結果:
3.從table中讀取但去掉重複值
程式碼:
SELECT DISTINCT title FROM titles
結果:4.從table中讀取滿足條件的資料
程式碼:
SELECT * FROM titles where title = 'staff'
結果:
5.AND運算子(找出first_name 是'Georgi'而且last_name是'Facello'的員工)
程式碼:
SELECT * FROM employees where first_name = 'Georgi' and last_name = 'Facello'
結果:
6.OR運算子(找出first_name
是'Georgi'或first_name 是'Parto'的員工)
程式碼:
SELECT * FROM employees where first_name = 'Georgi' or first_name = 'Parto'
結果:
7.結合
AND & OR(找出男性員工中,last_name 是'Koblick'或是'Facello'的員工)
程式碼:
SELECT * FROM employees where gender = 'M' and ( last_name = 'Koblick' or last_name = 'Facello' )
結果:
8.ORDER BY例項(找出所有員工,並依據birth_date排序)
程式碼:
SELECT * FROM employees ORDER BY birth_date
結果:
9.ORDER BY DESC例項(找出所有員工,並依據birth_date降序排序)
程式碼:
SELECT * FROM employees ORDER BY birth_date DESC
結果:
10.ORDER BY 多列例項(找出所有員工,並birth_date與first_name降序排序)
程式碼:
SELECT * FROM employees ORDER BY birth_date, first_name
結果: