首页 > 数据库技术 > 详细

数据库的查询

时间:2016-05-29 18:31:19      阅读:255      评论:0      收藏:0      [点我收藏+]

数据库的查询:
一、
【1】数据库的,增加内容
(1)insert into 表名 values(要添加的数据值‘‘,‘‘.....‘‘);

(2)insert into 表名 (列名1,列名2) values(‘列1对应的数值‘,‘列2对应的数值‘);


【2】数据库的,删除数据
delete from 表名 where 某列 = ‘数据‘
条件

【3】数据库的,修改数据
update 表名 set Name=‘李四‘ where Code=‘p001‘

二、查询数据

【1】简单查询
select * from Info

 

例1 查询全体学生的学号与姓名 

SELECT Sno,Sname FROM Student; 
<目标列表达式> 中各个列的先后顺序可以与表中的顺序不一致。

 

select Code as ‘代号‘,Name as ‘姓名‘ from Info

 【2】条件查询

select * from Car where Code=‘c002‘
select * from Car where Brand=‘b001‘ and Powers=130 或者用or      and两个条件瞒足      or并且,瞒足一条件    

【3】模糊查询
select * from Car where Name like ‘%奥迪%‘        %代表任意多个字符 _代表一个字符

【4】排序查询
select * from 表名 order by 列名1,Powers desc 降序       cas升序

【5】范围查询
select * from Car where Price>=40 and Price<=60
select * from Car where Price between 40 and 50

【6】离散查询
select * from Car where Code in (‘c001‘,‘c003‘,‘c005‘,‘c007‘)
select * from Car where Code not in(‘c001‘,‘c003‘,‘c005‘,‘c007‘)

【7】聚合函数,统计查询
select sum(Price) from Car #查询所有价格之和 sum()求和
select count(Code) from Car #查询数据条数
select max(Code) from Car #求最大值
select min(Brand) from Car #求最小值
select avg(Price) from Car #求平均值

【8】分页查询
#每页显示5条数据,取第2页的数据
select * from Car limit (n-1)*5,5

【9】去重查询
select distinct Brand from Car

【10】分组查询
select count(*),Brand from Car group by Brand
select Brand from Car group by Brand having count(*)>3 #分组之后根据条件查询使用having 不使用where

 

 

select * from 表名
select 列名1,列名2... from 表名 --投影
select * from 表名 where 条件 --筛选

 

数据库的查询

原文:http://www.cnblogs.com/yuyu1993/p/5539841.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!