轻松学习select查询语句(经典案例——本人自做)
2009-12-08 00:19
465 查看
-- 从当前系统中查询公用信息
select now()
-- 从表中查询所有字段
select * from pet
-- 给某些字段起别名
select `name` as aid, `sex` bid, species from pet
-- 对字段进行数学运算
select name, birth, birth+30 as manyue from pet
-- 去除掉重复记录。distinct影响到后续的所有字段
select distinct owner, name from pet
-- 多个条件用and or连接
select * from pet where owner='Gwen' or species = 'dog'
-- between and等同于>= and <=
select * from pet where birth>='1990-00-00' and birth<='1996'
select * from pet where birth between '1990-00-00' and '1996-00-00'
-- 下划线表示一个字符,%表示任意个字符
select * from pet where name not like 'b_%'
-- in表示多个条件的or
select * from pet where species='dog' or species='cat'
select * from pet where species not in ('dog', 'cat', 'bird')
-- 优先级顺序:not and or
select * from pet where (owner='gwen' or species='dog') and sex='M'
-- 列出90年代前出生的公狗和名字不以'F'开头的母猫
select * from pet where birth<'1990' and sex='m' and species='dog' or name not like 'f%' and sex='f' and species='cat'
-- 查询名字中包含'n'的人养的宠物有哪几种类型
select distinct species from pet where owner like '%n%'
-- null必须用is进行判断
select * FROM pet where death is not null
--
select * from pet where owner='gwen' order by name
-- 先按种类的降序排,再按生日的升序排
select * from pet order by species desc, birth
-- 查询条件不能用字段的别名,排序时可以使用
select name, species, birth as b
from pet
where birth>'1990'
order by b desc
-- 字符串的常见操作以字符为单位进行
select name, length(name), char_length(name),
concat(left(name,2), '...') as name
from pet
-- 单行函数可以在where条件中使用
select * from pet where left(name,1)='b'
-- 用两种方式查询出8月份出生、还没有死的宠物
-- 查询Gwen和Harold养的雌性的宠物,按主人和宠物的名字排列
-- 查询宠物的名字中包含有主人名字的第二个字母的宠物,按年龄排序
select now()
-- 从表中查询所有字段
select * from pet
-- 给某些字段起别名
select `name` as aid, `sex` bid, species from pet
-- 对字段进行数学运算
select name, birth, birth+30 as manyue from pet
-- 去除掉重复记录。distinct影响到后续的所有字段
select distinct owner, name from pet
-- 多个条件用and or连接
select * from pet where owner='Gwen' or species = 'dog'
-- between and等同于>= and <=
select * from pet where birth>='1990-00-00' and birth<='1996'
select * from pet where birth between '1990-00-00' and '1996-00-00'
-- 下划线表示一个字符,%表示任意个字符
select * from pet where name not like 'b_%'
-- in表示多个条件的or
select * from pet where species='dog' or species='cat'
select * from pet where species not in ('dog', 'cat', 'bird')
-- 优先级顺序:not and or
select * from pet where (owner='gwen' or species='dog') and sex='M'
-- 列出90年代前出生的公狗和名字不以'F'开头的母猫
select * from pet where birth<'1990' and sex='m' and species='dog' or name not like 'f%' and sex='f' and species='cat'
-- 查询名字中包含'n'的人养的宠物有哪几种类型
select distinct species from pet where owner like '%n%'
-- null必须用is进行判断
select * FROM pet where death is not null
--
select * from pet where owner='gwen' order by name
-- 先按种类的降序排,再按生日的升序排
select * from pet order by species desc, birth
-- 查询条件不能用字段的别名,排序时可以使用
select name, species, birth as b
from pet
where birth>'1990'
order by b desc
-- 字符串的常见操作以字符为单位进行
select name, length(name), char_length(name),
concat(left(name,2), '...') as name
from pet
-- 单行函数可以在where条件中使用
select * from pet where left(name,1)='b'
-- 用两种方式查询出8月份出生、还没有死的宠物
-- 查询Gwen和Harold养的雌性的宠物,按主人和宠物的名字排列
-- 查询宠物的名字中包含有主人名字的第二个字母的宠物,按年龄排序
相关文章推荐
- Oracle学习之路(一):oracle简介+基本sql语句+条件查询+排序数据理论与案例
- Oracle学习总结(5)—— SQL语句经典案例
- Oracle学习总结(5)—— SQL语句经典案例
- MySQL学习笔记(10)之select查询语句
- SQL语句学习手册实例版(本人整理,用来查询)
- Oracle学习之路(二):oracle多表查询+分组查询+子查询讲解与案例分析+经典练习题
- 学习 SQL 语句 - Select(3): 条件查询与模糊查询
- SQL语句学习手册实例版(本人整理,用来查询)
- 学习 SQL 语句 - Select(3): 条件查询与模糊查询
- sql server 2005 学习心得(select查询语句用法)
- sql语句查询(经典笔试题)
- sql 查询经典语句
- 经典SQL查询语句大全
- sql 查询经典语句
- 批处理学习:for语句详解【经典】
- 【jsp案例】通过select查询父类子类数据表
- ADO.NET select语句使用变量作为属性值的条件查询
- 查询表里面有N组相同的记录经典SQL语句
- 在oracle中,select语句查询字段中非纯数字值
- oracle心得3--多表查询@分组查询@子查询讲解与案例分析@经典练习题