• 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

  • 相关阅读:
    如何解除任务管理器被禁用
    一、JavaScript概述
    001_html基本结构
    postman常见问题记录
    fidder工具使用
    SonarQube工具使用问题汇总
    业余书籍读后感
    jmater常见问题处理
    测试知识记录(更新中)
    HTTP协议
  • 原文地址:https://www.cnblogs.com/selfimprove/p/3162552.html
Copyright © 2020-2023  润新知