欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MySql数据库中Select用法小结

程序员文章站 2023-12-16 23:23:58
一、条件筛选 1、数字筛选:sql = "select * from [sheet1$] where 销售单价 > 100" 2、字符条件:sql = "sele...

一、条件筛选

1、数字筛选:sql = "select * from [sheet1$] where 销售单价 > 100"

2、字符条件:sql = "select * from [sheet1$] where 物品名称 ='挡泥板'"

3、日期条件:sql = "select * from [sheet1$] where 物品名称 ='挡泥板'"

4、区间条件: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、借用函数优化:

'sql = "select * from [sheet1$] where left(物品代码,3)='028'"

二、指定筛选

1、筛选全部字段:*表示全部字段

'sql = "select * from chuku"

2、筛选指定字段:在from前面列出要显示的所有字段,如果要跳过的用""""

'sql = "select """",出库日期,"""",物品代码,"""",规格,单位 from chuku"

3、筛选不重复的:distinct 字段名 筛选不重复的记录

'sql = "select distinct """",物品代码 from chuku"

4、按百分比筛选:top n percent 可以显示前百分之n的记录

'sql = "select top 30 percent * from chuku"

'对筛选的字段用函数进行进一步的处理和格式化

'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" '筛选销售数量前10()

三、分组显示

group by 可以配合函数进行分组求和,分组求最大值等。

'sql = "select """","""",物品代码,"""","""","""",sum(出库数量) from chuku group by 物品代码" ' 跳过的用""""

按条件显示分组记录

'sql = "select """","""",物品代码,"""","""","""",sum(出库数量) from chuku group by 物品代码 having sum(出库数量)>=3"

以上所述是小编给大家介绍的mysql数据库中select用法小结,希望对大家有所帮助

上一篇:

下一篇: