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;

  • 相关阅读:
    百度搜索API v3版本与soap
    Yii整合ZF2及soap实例
    Getting started writing ZF2 modules
    js写出php中的函数系列
    一些有用的命令
    a标签至于flash之上的时候,IE浏览器无法点击连接的问题
    js问题集锦
    php常用函数集锦[备份用的]
    用过的一些js函数[备份用的]
    ELK
  • 原文地址:https://www.cnblogs.com/passzhang/p/12152567.html
Copyright © 2011-2022 走看看