模糊查询&&日期时间操作
一、模糊查询
1、采用“_”、“%”通配符进行查询
select * from Students where stu_name like '张_';--一个‘_’表示一个字符
select * from Students where stu_name like '张__'
select * from Students where stu_name like '_三';
select * from Students where stu_name like '张%';--%表示零个至多个字符
select * from Students where stu_name like '%三';
2、采用“[]”通配符进行查询
select stu_name from Students where stu_age like '1[0-9]';
select stu_name from Students where stu_age like '1[^7-9]';--不是7-9的
select stu_name from students where stu_name like '[^张]%';--查找不是姓张的学生的姓名
3、复杂模糊查询
select
学生姓名,年龄,性别,家庭住址
from
Students
where
学生姓名 like '张%'
and 年龄 like '2[2-7]'
and 家庭住址 like '河南%';
二、时间日期操作
1、判断是否是日期IsDate函数
select 学生编号,学生姓名,
case when IsDate(出生年月)=1 then '是日期信息'
else '不是日期信息'
end
as 生日字段是否是日期格式
from Students;
2、将日期类型数据转换为字符串
select 出生年月,
Substring(Convert(varchar(20),出生年月),6,5)
as 月日
from Students;
3、查询指定时间段的数据
select stu_name from students where stu_birthday between '1990-4-19' and '1991-05-03';
4、按年、月、日查询数据 Year Month Day
select 书号,书名,销售数量,日期 from tb_Book where Year(日期)='' and Month(日期)='' and Day(日期)=''
5、返回当前日期时间及对应的日期
select Getdate() as 当前日期时间,DATENAME(WEEKDAY,GETDATE()) as 星期;
6、查询指定时间间隔的数据
select 学生姓名,出生年月,Datediff(Year,出生年月,GetDate()) as 学生年龄 from tb_Student;
7、Not和谓词进行组合条件的查询
select * from Students where stu_math not Between 70 and 80;
8、Having子句:聚合不应出现在 WHERE 子句中,除非该聚合位于 HAVING 子句或选择列表所包含的子查询中,并且要对其进行聚合的列是外部引用。
select count(书号) as 记录条数,书号,书名,作者 from tb_Book Group By 书号,书名,作者 Having count(书号)>1;
模糊查询&&日期时间操作的更多相关文章
- Firebird日期时间操作
最近在使用Firebird数据做 一项目,使用FireBird边用边学.(以下转贴) 查询2007年度以后的,12月份以上的数据记录,datetime为timestamp字段 select * fro ...
- paip.日期时间操作以及时间戳uapi php java python 总结
paip.日期时间操作以及时间戳uapi php java python 总结 ///uapi Date 函数 | Day 函数 | Hour 函数 | Minute 函数 | Month 函数 | ...
- Python基础 | 日期时间操作
目录 获取时间 时间映射 格式转换 字符串转日期 日期转字符串 unixtime 时间计算 时间偏移 时间差 "日期时间数据"作为三大基础数据类型之一,在数据分析中会经常遇到. 本 ...
- Java日期时间操作基础——包含JDK1.8时间操作新特性
JDK1.7日期时间操作 示例小结 public class DateTest { public static final String FORMAT_DATE = "yyyy-MM-dd& ...
- MySQL tips (日期时间操作/concat 等)
1. Query结尾要加一个分号: 2. 数据库和表 SHOW DATABASES; USE YOUR_DB; SHOW TABLES; SHOW COLUMNS FROM study或者D ...
- JS 中的日期时间操作计算实例
实例 一:已知日期格式为 "YYYY/MM/DD",计算相对于今天的天数差. function fromNow(date){ var mTimes = new Date(date) ...
- Java日期时间操作的一些方法
1. 获得Calendar实例: Calendar c = Calendar.getInstance(); 2. 定义日期/时间的格式: SimpleDateFormat sdf =new Simpl ...
- php 日期时间操作-可算出几天后的时间
本文为大家介绍一下根据PHP时间戳获取当前时期的具体方式.strtotime能将任何英文文本的日期时间描述解析为Unix时间戳,我们结合mktime()或date()格式化日期时间获取指定的时间戳,实 ...
- mysql日期时间操作
select curdate(); --获取当前日期 select last_day(curdate()); --获取当月最后一天. select DATE_ADD(curdate(),interva ...
随机推荐
- git从入门到精通
1.git简介 由Linus在2005年花了两周时间完成,也就是开发Linux系统的大神研制. git特点: 自由和开放源码 隐形备份 安全 不需要强大的硬件 更简单的分支 对文件操作容易 2.文件操 ...
- memcached搭建缓存系统
Memcached是danga.com(运营LiveJournal的技术团队)开发的一套分布式内存对象缓存系统,用于在动态系统中减少数据库负载,提升性能. 二.适用场合 1.分布式应用.由于memca ...
- iOS调试 LLDB
LLDB是个开源的内置于XCode的具有REPL(read-eval-print-loop)特征的Debugger,其可以安装C++或者Python插件. 常用调试命令: 1.print命 ...
- 隐藏vbs执行cmd命令的窗口
dim obj_shellset obj_shell = createobject("wscript.shell") host = WScript.FullNameIf LCase ...
- BG雪碧图制作要求
使用软件 firework 保存png-8 然后参数如下图: 格式:PNG 8 调色板:最适合 深度:128 透明度:Alpha 透明度
- 关于TCP协议握手的那些事儿
旁白 今天面了下鹅场的后台技术开发,面试官问了我关于TCP连接协议的3次握手和断开连接协议的4次握手的问题.因为之前看过TCP的连接和断开处理,但是印象没有那么深刻.我想主要原因是一直重复简单的记忆, ...
- JS 和 CSS 的位置对其他资源加载顺序的影响
JS 和 CSS 在页面中的位置,会影响其他资源(指 img 等非 js 和 css 资源)的加载顺序,究其原因,有三个值得注意的点: JS 有可能会修改 DOM. 典型的,可能会有 document ...
- Use EnCase to acquire data from a smartphone
Yesterday someone asked me a question can EnCase acquire data from a smartphone, and my reply was &q ...
- hdu2444
#include <stdio.h> #include <string.h> #define black 1 #define white -1 ]; ]; ][]; int n ...
- 将Application按钮从任务栏中去掉
SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);