[首页]
[文章]
[教程]
首页
Web开发
Windows开发
编程语言
数据库技术
移动平台
系统服务
微信
设计
布布扣
其他
数据分析
首页
>
数据库技术
> 详细
数据库查询汇总
时间:
2019-04-13 22:23:22
阅读:
115
评论:
0
收藏:
0
[点我收藏+]
转载
原文地址:http://blog.csdn.net/liuxinmingcode/article/details/51554061
select
select *
from student;
all 查询所有
select all sex
from student;
distinct 过滤重复
select
distinct sex
from student;
count 统计
select
count(*)
from student;
select
count(sex)
from student;
select
count(
distinct sex)
from student;
top 取前N条记录
select top
3 *
from student;
alias column name 列重命名
select
id
as 编号,
name ‘名称’, sex 性别
from student;
alias table name 表重命名
select
id,
name, s.id, s.name
from student s;
column 列运算
select (age +
id)
col
from student;
select s.name + ‘-’ + c.name
from classes c, student s
where s.cid = c.id;
where 条件
select *
from student
where
id =
2;
select *
from student
where
id >
7;
select *
from student
where
id <
3;
select *
from student
where
id <>
3;
select *
from student
where
id >=
3;
select *
from student
where
id <=
5;
select *
from student
where
id !>
3;
select *
from student
where
id !<
5;
and 并且
select *
from student
where
id >
2
and sex =
1;
or 或者
select *
from student
where
id =
2
or sex =
1;
between … and … 相当于并且
select *
from student
where
id
between
2
and
5;
select *
from student
where
id
not
between
2
and
5;
like 模糊查询
select *
from student
where
name
like ‘%a%’;
select *
from student
where
name
like ‘%[a][o]%’;
select *
from student
where
name
not
like ‘%a%’;
select *
from student
where
name
like ‘ja%’;
select *
from student
where
name
not
like ‘%[j,n]%’;
select *
from student
where
name
like ‘%[j,n,a]%’;
select *
from student
where
name
like ‘%[^ja,
as,
on]%’;
select *
from student
where
name
like ‘%[ja_on]%’;
in 子查询
select *
from student
where
id
in (
1,
2);
not in 不在其中
select *
from student
where
id
not
in (
1,
2);
is null 是空
select *
from student
where age
is
null;
is not null 不为空
select *
from student
where age
is
not
null;
order by 排序
select *
from student
order
by
name;
select *
from student
order
by
name
desc;
select *
from student
order
by
name
asc;
group by 分组
按照年龄进行分组统计
select
count(age), age
from student
group
by age;
按照性别进行分组统计
select
count(*), sex
from student
group
by sex;
按照年龄和性别组合分组统计,并排序
select
count(*), sex
from student
group
by sex, age
order
by age;
按照性别分组,并且是id大于2的记录最后按照性别排序
select
count(*), sex
from student
where
id >
2
group
by sex
order
by sex;
查询id大于2的数据,并完成运算后的结果进行分组和排序
select
count(), (sex
id)
new
from student
where
id >
2
group
by sex *
id
order
by sex *
id;
group by all 所有分组
按照年龄分组,是所有的年龄
select
count(*), age
from student
group
by all age;
having 分组过滤条件
按照年龄分组,过滤年龄为空的数据,并且统计分组的条数和现实年龄信息
select
count(*), age
from student
group
by age
having age
is
not
null;
数据库查询汇总
原文:https://www.cnblogs.com/woyaozilv/p/10703088.html
踩
(
0
)
赞
(
0
)
举报
评论
一句话评论(
0
)
登录后才能评论!
分享档案
更多>
2021年09月23日 (328)
2021年09月24日 (313)
2021年09月17日 (191)
2021年09月15日 (369)
2021年09月16日 (411)
2021年09月13日 (439)
2021年09月11日 (398)
2021年09月12日 (393)
2021年09月10日 (160)
2021年09月08日 (222)
最新文章
更多>
2021/09/28 scripts
2022-05-27
vue自定义全局指令v-emoji限制input输入表情和特殊字符
2022-05-27
9.26学习总结
2022-05-27
vim操作
2022-05-27
深入理解计算机基础 第三章
2022-05-27
C++ string 作为形参与引用传递(转)
2022-05-27
python 加解密
2022-05-27
JavaScript-对象数组里根据id获取name,对象可能有children属性
2022-05-27
SQL语句——保持现有内容在后面增加内容
2022-05-27
virsh命令文档
2022-05-27
教程昨日排行
更多>
1.
list.reverse()
2.
Django Admin 管理工具
3.
AppML 案例模型
4.
HTML 标签列表(功能排序)
5.
HTML 颜色名
6.
HTML 语言代码
7.
jQuery 事件
8.
jEasyUI 创建分割按钮
9.
jEasyUI 创建复杂布局
10.
jEasyUI 创建简单窗口
友情链接
汇智网
PHP教程
插件网
关于我们
-
联系我们
-
留言反馈
- 联系我们:wmxa8@hotmail.com
© 2014
bubuko.com
版权所有
打开技术之扣,分享程序人生!