模糊查询&&日期时间操作
一、模糊查询
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 ...
随机推荐
- VIM安装 NERDTREE,SOLARIZED 插件
实验系统版本及VIM版本 系统:CentOS6.3 VIM:7.2 插件介绍 (附上一张效果图) nerdtree(在窗口左侧用于浏览目录结构的插件) solarized(一个自己认为比较护眼的vim ...
- break 和 continue
break 和 continue 相同点: 都 用在循环体内,如 switch.for.while.do while的程序块中,用于控制程序循环语句的执行 不同点: break可以离开当前switch ...
- hive添加分区
添加分区 alter table 表名 add partition (dt='2016-09-12'); select * from 表名 where dt = '2016-09-12' limit ...
- [oracle] listener.ora 、sqlnet.ora 、tnsnames.ora
路径 $ORACLE_HOME/network/admin sqlnet.ora(客户及服务器端) 作用类似于linux或者其他unix的nsswitch.conf文件,通过这个文件来决定怎么样找一个 ...
- MapReduce和Tez对比
MapReduce是一种编程模型,用于大规模数据集(大于1TB)的并行运算.概念"Map(映射)"和"Reduce(归约)". Tez是Apache开源的支持D ...
- Leetcode006 ZigZag Conversion
/* simple simulation algorithm * we cann`t make sure the size of the string, * so it had better to s ...
- WF4.0 Activities<第一篇>
一.基元工具 1.Delay Delay用于延迟一段时间执行下面的流程.在WF中实例是单线程运行的,Delay并不是Thread.Sleep方法实现的. Delay有一个Duration属性,用于设置 ...
- Android事件
1.Java package com.fish.helloworld; import android.app.Activity; import android.graphics.Color; impo ...
- EasyUI-Combox
Combox的数据格式和默认选中项设置 [{ "id":1, "text":"text1" },{ "id":2, &q ...
- oracle 数组类型
create or replace function my_test(p_str varchar2) return number as --普通变量 v_var ); --固定长度数组 type v_ ...