一、條件篩選
1、數(shù)字篩選:sql = "Select * from [sheet1$] Where 銷售單價 > 100"
2、字符條件:sql = "Select * from [sheet1$] Where 物品名稱 ='擋泥板'"
3、日期條件:sql = "Select * from [sheet1$] Where 物品名稱 ='擋泥板'"
4、區(qū)間條件:sql = "Select * from [sheet1$] Where 出庫日期 between #2005-1-4# and #2005-1-10#"
5、多個條件:用and,OR連接
'sql = "Select * from [sheet1$] Where 出庫日期 between #2005-1-4# and #2005-1-10# and 銷售單價>100"
6、模糊條件:%表示任意多個字符,_(下劃線)表示單個占位符
'sql = "Select * from [sheet1$] Where 物品名稱 like '%扶手%'"
7、插入變量查詢:
'sr = "擋泥板"
'sql = "Select * from [sheet1$] Where 物品名稱 ='" sr "'"
8、在字符串組里:
'sql = "Select * from [sheet1$] Where 物品名稱 in('車衣','扶手箱')"
9、借用函數(shù)優(yōu)化:
'sql = "Select * from [sheet1$] Where left(物品代碼,3)='028'"
二、指定篩選
1、篩選全部字段:*表示全部字段
'sql = "Select * from ChuKu"
2、篩選指定字段:在from前面列出要顯示的所有字段,如果要跳過的用""""
'sql = "Select """",出庫日期,"""",物品代碼,"""",規(guī)格,單位 from ChuKu"
3、篩選不重復的:Distinct 字段名 篩選不重復的記錄
'sql = "Select Distinct """",物品代碼 from ChuKu"
4、按百分比篩選:Top N percent 可以顯示前百分之N的記錄
'sql = "Select top 30 Percent * from ChuKu"
'對篩選的字段用函數(shù)進行進一步的處理和格式化
'sql = "Select ID,Format(出庫日期,""yyyy-mm-dd"") from ChuKu"
5、排序:Desc降序,Asc升序
'sql = "Select * from ChuKu Order by 出庫日期 asc,銷售單價 desc"
'sql = "Select Top 10 * from ChuKu Order by 出庫日期 asc,銷售單價 desc" '篩選銷售數(shù)量前10()
三、分組顯示
Group by 可以配合函數(shù)進行分組求和,分組求最大值等。
'sql = "Select """","""",物品代碼,"""","""","""",sum(出庫數(shù)量) from ChuKu group by 物品代碼" ' 跳過的用""""
按條件顯示分組記錄
'sql = "Select """","""",物品代碼,"""","""","""",sum(出庫數(shù)量) from ChuKu group by 物品代碼 HAVING sum(出庫數(shù)量)>=3"
以上所述是小編給大家介紹的MySql數(shù)據(jù)庫中Select用法小結(jié),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
您可能感興趣的文章:- 淺談MySQL之select優(yōu)化方案
- MySQL將select結(jié)果執(zhí)行update的實例教程
- 解決MySQL讀寫分離導致insert后select不到數(shù)據(jù)的問題
- MySQL Select語句是如何執(zhí)行的
- MySQL之select in 子查詢優(yōu)化的實現(xiàn)
- mysql學習筆記之完整的select語句用法實例詳解
- MySQL select、insert、update批量操作語句代碼實例
- 簡單了解MySQL SELECT執(zhí)行順序
- mysql事務select for update及數(shù)據(jù)的一致性處理講解
- MySQL中Update、select聯(lián)用操作單表、多表,及視圖與臨時表的區(qū)別
- mysql select緩存機制使用詳解
- 論一條select語句在MySQL是怎樣執(zhí)行的