• 常见sql语句


    # 1.查询出来 user 表中 score 大于 80 的所有数据

    select * from user where score >80;
    # 2.查询表 user 中字段 gender 为 '男' 的所有内容
    select * from user where gender = '男';
    # 3.查询表 user 中字段 students 开头为'小'字的内容
    select * from user where students like'小%';
    # 4.查询表 user 中字段 students 开头不是为'小'字的内容
    select * from user where students not like '小%';
    # 5.查询表 user 中字段 students 包含'聪'字的所有内容
    select * from user where students like'%聪%';
    # 6.查询表 user 中字段 score 为98,60,92的所有内容
    select * from user where score in(98,60,92);
    # 7.查询表 user 中字段 score 大于95 或者 gender 为女性的所有内容
    select * from user where score > 95 or gender == '女';
    # 8.合并查询表 user 和表 user_ext 中 id 相同的所有数据
    select * from user,user_ext where user.id=user_ext.id;
    # 9.获取表 user 中字段 score 大于 60 的内容数量
    select count(*) from user where score > 60;
    # 10.获取表 user 中字段 score 的平均值
    select avg(score)from user;
    # 11.获取表 user 中字段 score 的总分数
    select sum(score)from user;
    #12.获取表 user 中字段 score 的最大值
    select max(score) from user
    #13.获取表 user 中字段 score 的最小值
    select min(score) from user
    #14.获取表 user_ext 中所有不同的字段 age 并设置字段别名为'年龄'
    select id,students,age '年龄',height,weight
    from user_ext
    #15.获取表 user_ext 中的所有数据并且按照字段 weight 进行倒序排序
    select * from user_ext
    order by weight desc
    #16.通过左连接 获取表 user(别名t1) 和表 user_ext(别名t2) 中字段 id 相同的数据
    #其中字段 age 大于9,并仅返回 id、students、age、weight 这几个字段的数据
    select t1.id,t1.students,t2.age,t2.weight
    from user t1
    left join user_ext t2
    on t1.id = t2.id
    where age > 9
    #17.在 user 表 所有字段 中添加记录
    insert into user values(7,'小敏',99,'女')
    #18.把 user 表 中字段 students 为'小明' 所在字段 score 更改为30分
    update user set score = 30 where students = '小明'
    #19.把 user 表 students 字段为'小明'的记录删除
    delete from user where students = '小明'
    #20.删除user_ext表
    drop table user_ext

  • 相关阅读:

    java 线程池
    java 普通内部类和静态内部类
    JVM
    java httpUtil
    maven 常见问题
    计算java对象的内存占用
    HTML5简单入门系列(九)
    HTML5简单入门系列(八)
    HTML5简单入门系列(七)
  • 原文地址:https://www.cnblogs.com/l-x-l-1217/p/13633046.html
Copyright © 2020-2023  润新知