常用sql语句

写在前面

创建表‘sc’代表学生成绩单;
创建属性‘con’代表‘课程’,容我失策‘cno’写成‘con’;
创建属性‘sno’代表学生的学号;
创建属性‘score’代表分数;


基础篇

  1. 查询所有列:*代表all
    select * from sc;

  2. 查询指定列:直接加属性名
    select score from sc;

  3. 去重:添加‘distinct’
    select distinct score from sc;

  4. 条件查询:添加where,还有like、in、and、or
    select score from sc where score>70;

  5. 排序:order by 属性
    select score from sc order by score desc(/asc);

  6. 分页:前面pageindex,后面pagenumber
    select * from sc limit 0,5;
    select * from sc limit 5,5;

  7. 插入
    insert into sc (con,sno,score)values(1,11,99);

  8. 更新
    update sc set score = 88 where sn0 = 11;

  9. 删除
    delete from sc where sno = 10;

  10. as
    select distinct a.sno from
    (select sno,score from sc where con = 1) a,
    (select sno,score from sc where con = 2)b
    where a.score > b.score
    order by a.sno
    limit 0,10;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 50个常用的sql语句Student(S#,Sname,Sage,Ssex) 学生表Course(C#,Cname...
    哈哈海阅读 1,261评论 0 7
  • 50个常用的sql语句 Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cna...
    最美的太阳WW阅读 3,247评论 0 23
  • @(〓〓 iOS-实用技术)[SQLite 数据库] 作者: Liwx 邮箱: 1032282633@qq.co...
    Liwx阅读 3,203评论 0 40
  • ##一、数据库操作: ** 1、查看数据库: ** >SHOW DATABASES; ** 2、创建数据库: **...
    smallBear阅读 305评论 0 1
  • 感觉好久没有出门了,还有想去找个屏幕来修那个老恩刚捡到的手机。今天 早上起来就去了华强北 好久没有一件真正有目的...
    骆驼和马阅读 425评论 0 3