美文网首页
常用sql语句

常用sql语句

作者: 骑蜗牛兜风 | 来源:发表于2017-09-25 19:11 被阅读25次

    写在前面

    创建表‘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;

    相关文章

      网友评论

          本文标题:常用sql语句

          本文链接:https://www.haomeiwen.com/subject/ymedextx.html