• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
我的学习笔记
   首页       联系   管理    订阅  订阅

SQL数据库语句

查询语句 select * From authors 对字段进行查询 select au_lname,an_fname,city From authors
查询语句
select * From authors

对字段进行查询
select au_lname,an_fname,city From authors

满足特定条件搜索
select an_lname,an_fname,city From authors Where city='Oakland'

复杂条件搜索
select * From sales Where qty>25 and odr_date Between '1993-1-1' and '1994-1-1'
select * From sales Where (qty<25 or qty>40) and ord_date<'1994-1-1'  //搜索qty小于25或大于40并且ord-date小于1994年1月1日的数据

模糊查询
select * From authors Where au_lname LIKE 'S'   //搜索表authors中au_lname字段以S开头的数据 
                                                      S通配多个字符   ?通配一个字符

排序 ORDER BY 语句
    升序以ASC标识(默认)
    降序以DESC标识
select * From sales ORDER BY qty
select * From sales Where qty<30 ORDER BY qty DESC   // 搜索表sales中qty字段中大于30的数据并以降序排列

限定查询
select distinct stste Form authors   //distinct操作符  state字段

统计(对限定内容统计)
select Count(state) From authors   //统计有多少个state有相同的
select Count(Distinct state) As stst_num From authors    //查询有几个不同的state,统计为列名stst_num的

Max函数 数值类型字段的最大值
Min函数 数值类型字段的最小值
Avg函数 数值类型字段的平均值

插入记录INSERT
   在sales表中插入一条新记录
Insert sales(stor_id,ord_num,ord_date,qty,payterms,title_id) value ('8043','F335','1994-5-6','Net40','pc1035')
在插入时如已指定所有字段的值,可以简写成
Insert sales value ('8043','F335','1994-5-6','Net40','pc1035')
查询创建是否成功
select * from sales Where ord_date='1994-5-6'

修改记录UPDATE
UPDATE authors set photo='801826-0755',state='UT',zip='84152' where au_id='998-72-4000'
select * From authors where au_id='998-72-4000'

删除记录DELECT
 1.删除全部记录 
Delect tablename  //表名
 2.删除满足条件记录的语句
Delect tablename where fieldn=valuen
 例:
Delect authors where au_id='998-72-4000'
select *From authors where au_id='998-72-4000'
posted @ 2007-11-10 20:35  吴有鋆  阅读(876)  评论(5)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3