• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

不爱学习不爱运动

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

1.sql练习-在线练习笔记

链接:http://sample.jimstone.com.cn/xsql/Course/18.html

一、查询

1.合并查询表 user 和表 user_ext 中 id 相同的所有数据

 select * from user , user_ext  where  user.id = user_ext.id

2. 获取表 user 中字段 score 大于 60 的内容数量

 select count(*) from user where score > 60

3.获取表 user 中字段 score 的平均值

 select AVG(score) from user

4. 获取表 user 中字段 score 的总分数

select SUM(score) AS sumScore from user 

5.获取表 user 中字段 score 的最大值

select MAX(score) AS maxScore from user

6.获取表 user 中字段 score 的最小值

select MIN(score) AS minScore from user

7.获取表 user_ext 中所有不同的字段 age 并设置字段别名为'年龄'

 select DISTINCT(age) AS 年龄 from user_ext

8.获取表 user_ext 中的所有数据并且按照字段 weight 进行倒序排序

 select * from user_ext ORDER BY weight DESC

 左连接  left join....on

9.通过左连接 获取表 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 t1.id = t2.id where t2.age > 9

二、增

10.在 user 表 所有字段 中添加记录

 INSERT INTO user(students,score,gender) VALUES('大红', 100,'男');

三、改

11. 把 user 表 中字段 students 为'小明' 所在字段 score 更改为30分

update user set score=30 where students = '小明'

四、删

12. delete from user where students = '小明';

五、创建表

create table test(id int primary key, name varchar(20), gender varchar(2))

六、删除表

drop table test;

 

posted on 2020-08-19 11:10  不爱学习不爱运动  阅读(62)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3