• SQL练习1关于插入删除,修改,单表查询


    --创建数据库
    create database studentsDB

    --创建表
    create table student
    (
     id int primary key,
     stuid char(10),
     stuname char(20),
     classname char(20),
     addresss char(40),
     cols int,
     sex char(10)
    )

    --更改数据项的数据类型
    alter table student
    alter column cols float

    --插入数据
    insert into student(id,stuid,stuname,classname,addresss,cols,sex)
    values(1,'001','张三','1','重庆',100,'男')

    insert into student(id,stuid,stuname,classname,addresss,cols,sex)
    values(2,'002','李四','2','四川',70,'女')

    insert into student(id,stuid,stuname,classname,addresss,cols,sex)
    values(3,'003','李丽','1','贵州',99,'男')

    insert into student(id,stuid,stuname,classname,addresss,cols,sex)
    values(4,'004','王五','3','武汉',55,'女')

    insert into student(id,stuid,stuname,classname,addresss,cols,sex)
    values(5,'005','陈好','1','香港',67,'男')

    --查询分数在60-100的信息
    select id,stuid,stuname,classname,addresss,cols,sex from student where cols between 60 and 100

    --查询班级里姓李的同学的信息
    select id,stuid,stuname,classname,addresss,cols,sex from student where stuname like '李%'

    --查询分数等于99和100的同学的信息
    select id,stuid,stuname,classname,addresss,cols,sex from student where cols = 99 or cols =100

    --根据分数降序排列
    select id,stuid,stuname,classname,addresss,cols,sex from student order by cols desc

    --根据性别求出男生和女生分数的平均值
    select avg(cols) as 平均成绩,sex from student group by sex

    --求出各班的平均成绩
    select avg(cols) as 平均成绩,classname from student group by classname

  • 相关阅读:
    前端/html5效果收藏
    Fiddler 网页采集抓包利器
    Es6 类class的关键 super、static、constructor、new.target
    js 倒计时毫秒级别显示
    雅虎34条军规
    javascript 异步请求封装成同步请求
    微信小程序 base64图片在canvas上画图
    chrome inspect 远程调试H5
    webpack 打包调试
    微信小程序云函数 添加数据到数据库
  • 原文地址:https://www.cnblogs.com/selfimprove/p/3162552.html
Copyright © 2020-2023  润新知