学习sql语句的时候,我在一本书上选取的例子
先下载mdb文件client.rar,再在sql视图中执行以语句,看返回的结果是不是和你的理解一致:
选取全部栏位
select * from ct(表名称)
选取部分栏位
select name,notes,times from ct
改变栏位名称
select name as 姓名,notes as 备注,birthday as 生日 from ct
条件运算式一
1.针对数字类型的栏位
select * from ct where times>5
条件运算式二
针对字符串
select * from ct where name like'*刘*'
'*刘*' name栏包含刘即可
'刘*'以刘开头的才可
'*刘'以刘结尾的才可
'刘'只有刘时才可
条件运算式三
日期类型的数据比较(不可以用like来比较)
select *from ct where birthday >#1978/1/1#
条件运算式四
对于true/false,yes/no,on/off
select * from ct where vip=true
多重条件运算式
and,or,not ,like等多重条件下
select * from ct where vip=false or notes like '*女孩*'
排序
asc递增,desc递减
select * from ct order by times desc
select * from ct order by name desc,times asc
between
选取某一范围内的数据
select * from ct where times between 5 and 7
栏位间比较
select * from ct where times < id
in
select * from ct where id in (1,3,5,7,9)
链接表
链接多表成为新的表
select ct.name,ct.birthday,ct.vip,place.country from ct,
place where ct.living=place.id
计算式栏位
select name,birthday+2,times+3 from ct
统计查询
对数字
avg平均数
max最大值
min最小值
stdev数据样本之标准差
stdevp数据母体之标准差
sum总合
var数据样本之变异数
varp数据母体之变异数
select sum(times) as 总合,avg(times) as 平均 from ct
Insert 新增
新增栏位
insert into place (country) values('england')
Delete
delete from ct where id =2
delete all:
delete from ct
update
update ct set vip=true ,notes="nice to go" where id =3
update ct set times=times*2
ps:散乱记录
sql = "select top 9 * from CMS_Nav where CMS_Sid=0 order by CMS_ID ASC" ‘sql限制选择数目