zoukankan      html  css  js  c++  java
  • 常见SQL命令总结学习 -- <1>

    SQL学习网练习记录

    参考1:http://sample.jimstone.com.cn/xsql/Course/4.html
    参考2:http://sample.jimstone.com.cn/xsql/Course/

    1. 本课要求:查询表 user 的所有内容
      select * from user;

    2. 本课要求:查询出来 user 表中 score 大于 80 的所有数据
      select * from user where score > 80;

    3. 本课要求:查询表 user 中字段 gender 为 '男' 的所有内容
      select * from user where gender='男';

    4. 本课要求:查询表 user 中字段 students 开头为'小'字的内容
      select students from user where students like '小%';

    5. 本课要求:查询表 user 中字段 students 开头不是为'小'字的内容
      select * from user where students not like '小%';

    6. 本课要求:查询表 user 中字段 students 包含'聪'字的所有内容
      select * from user where students like '%聪%';

    7. 本课要求:查询表 user 中字段 score 为98,60,92的所有内容
      select * from user where score in (98,60,92);

    8. 本课要求:查询表 user 中字段 score 大于95 或者 gender 为女性的所有内容
      select * from user where score>'95' or gender='女';

    9. 本课要求:合并查询表 user 和表 user_ext 中 id 相同的所有数据
      select * fom user,user_ext where user.id=user_ext.id;

    10. 本课要求:获取表 user 中字段 score 大于 60 的内容数量
      select count(*) from user where score>'60';
      select * from user where score>'60';

    11. 本课要求:获取表 user 中字段 score 的平均值
      select avg(score) from user;
      select score from user;

    12. 本课要求:获取表 user 中字段 score 的总分数
      select sum(score) as sumvalue from user;

    13. 本课要求:获取表 user 中字段 score 的最大值
      select max(score) as maxvalue from user;

    14. 本课要求:获取表 user 中字段 score 的最小值
      select min(score) as minvalue from user;

    15. 本课要求:获取表 user_ext 中所有不同的字段 age 并设置字段别名为'年龄'
      select distinct(age) as 年龄 from user_ext;

    16. 本课要求:获取表 user_ext 中的所有数据并且按照字段 weight 进行倒序排序
      select * from user_ext order by weight desc;

    17. 本课要求:通过左连接 获取表 user(别名t1) 和表 user_ext(别名t2) 中字段 id 相同的数据,其中字段 age 大于9,并仅返回 id、students、age、weight 这几个字段的数据
      select t1.id,t1.students,t2.age,t2.weight from user as t1 left join user_ext as t2 on t2.id=t1.id where t2.age>9;

    18. 本课要求:在 user 表 所有字段 中添加记录
      insert into user(students,score,gender) values ('小蜗牛','100','男');

    19. 本课要求:把 user 表 中字段 students 为'小明' 所在字段 score 更改为30分
      update user set score=30 where students='小明';

    20. 本课要求:把 user 表 students 字段为'小明'的记录删除
      delete from user where students='小明';

    21. 本课要求:创建一个名为'test'的表
      create table test(id integer primany key,students varchar(8),score integer,gender varchar(2));

    22. 本课要求:把'test'表 删除
      drop table test;

  • 相关阅读:
    明明已经include_once() 但还是报错Class 'XXXXXControllerTOPData' not found
    dell U2515H 2k显示器黑屏问题,dp线问题。
    centos7.4 php5升级到php7
    thinkphp批量插入 更新sql
    查询速度慢了10倍,查询条件类型不对,字符串当做数字类型。
    margin-left:auto;margin-right:auto; 不起作用的原因
    jquery 查找元素,id,class
    php分割url,获取参数query
    阿里云服务器删除日志的方法,查看有哪些大文件
    sql优化 分字段统计查询
  • 原文地址:https://www.cnblogs.com/Serverlessops/p/12152567.html
Copyright © 2011-2022 走看看