美文网首页
操作数据表中的记录

操作数据表中的记录

作者: Ming_0612 | 来源:发表于2018-02-25 01:07 被阅读0次
    image.png image.png

    insert users3 values(default,'tom','123',default,1);单个
    insert users3 values(default,'tom','123',3*7-5,1),(null,'rose',md5('123'),default,0);多个

    image.png

    insert users3 set username='ben',password='456';

    image.png

    insert test(username) select username from users3 where age>=30;//把users3表中的age大于等于30的username列中的数据放到test表中的username列去

    image.png
    update users3 set age=age+5;
    age列中的值都加五
    update users3 set age=age-id,sex=0;
    age列中的值都分别减去id,并且把sex列的值都改为0
    update users3 set age=age+10 where id%2=0;
    把id列中为偶数的age列中的值都加上10 image.png

    delete from users3 where id=6;
    删除id是六的行

    image.png
    image.png

    select id,username from users3;//查找users3中的id,username列
    select users3.id,users3.username from users3;//这个的话,方便多表连接,以后还能users2.啥啥啥吧
    select id as userid,username as uname from users3;//以userid作为id的别名,uname作为username的别名,输出这两列的值

    image.png image.png
    image.png

    select sex from users3 group by sex;//从sex列中找出不同的组别。。。。。


    image.png
    select sex,id,username,age from users3 group by username;//从sex,id,username,age中找出因为username不同而不同的组别
    image.png image.png

    select username,age from users3 group by 1 having age>35;//选择age大于35的数据,输出它的姓名和年龄
    select sex from users3 group by 1 having count(id)>=2;//选择id的数目大于等于2的sex的值,数目也就是说。。有多少个id值,比如说null就只有一个id所以不输出null

    image.png

    select *from users3 order by age desc;//根据年龄降序排列输出
    select *from users3 order by age desc ,id desc;//根据先年龄降序排列,若有相同的年龄则根据id降序排列输出

    image.png
    selectfrom users3 limit 2;//从头开始输出两行
    select
    from users3 limit 2,2;//输出第三第四行,因为表是从0开始编号的
    select *from users3 order by id desc limit 2,2;//输出从排序后的表的第三第四行

    相关文章

      网友评论

          本文标题:操作数据表中的记录

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