VB6.0(第十三课)之sql

一、SQL:结构化查询语言

二、语句
1、检查数据:select

select [all | distinct ] 
       [top n [percent] [with ties]]
       <select_list>
       <select_list>...
       {  *
           |{ table_name | view_name | table_alias}  *
           .....}
           ```1```sql
select name from tb_employee

(2)

select number,name,sex from tb_employee

(3)

select * from tb_employee

2、排序
(1)按编号(number)升序排序

select number,name,sex from tb_employee  order by number

(2)按编号(number)、年龄(sex)排序

select number,name,sex,age from tb_employee  order by age,number

(3)按列位置。(第4列:age,第1列:number)

select number,name,sex,age from tb_employee  order by 4,1

(4)按年龄(age)降序排序

select number,name,sex,age from tb_employee  order by age DESC

(5)按年龄(age)降序排序,再按编号(number)排序

select number,name,sex,age from tb_employee  order by age DESC , name

(6)对新生成的列进行排序
将图书数据中,单本版税最高的书排在第一位。

select title,price * royalty/100 as royalty_per_unit from titles order by royalty_per_unit desc

3、过滤数据(where子句)
(1)

select number,name,sex,age from tb_employee  where age=28

(2)运算符:=、>= <= <> !<(不小于)

select number,name,sex,age from tb_employee  where age>=28

4、检索指定范围的值(between)
(1)年龄在28~34之间的员工

select number,name,sex,age from tb_employee  where age between 28 and 34

5、模式条件查询
通配符:%(零个或任意多个字符串)、_(任意单个字符)、[](指定范围)
(1)姓张

select number,name,from tb_employee  where name like '张%'

(2)下划线(_)通配符
姓名中第二字为“强”的

select number,name,from tb_employee  where name like '_强'

(3)查询电话号码以“110”结尾且开头数字位于1~5之间的员工信息。

select * from tb_employee where phone like '[1-5]30110'

(4)and、or、not

select * from tb_employee where name like '张%' or name like '李%'

6、汇总数据
VB6.0(第十三课)之sql_第1张图片

select sex,AVG(age) as 平均年龄 from tb_employee group by sex
select count(number) as 员工人数 from tb_employee
select max(age) as 最大年龄  from tb_employee
select sum (realitypay) as 工资发放总额  from tb_pay

7、分组统计、子查询

8、插入数据
(1)插入完整行

insert into tb_employee values('00030','小李','女','2220000','1980-02-01','41','汉族','96784')

(2)插入部分行

insert into tb_employee(number,name)  values('00031','小王')

(3)

insert into 月消费信息表  select * from 日消费信息表

9、修改、删除数据
(1)修改数据

delete from table_name where search_conditions
delete from tb_employee    '删除表中所有的数据
delete from tb_employee where age < 23

你可能感兴趣的:(vb6.0)