zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Entityframework的简单应用
    vs2012搭建gtest环境
    Just Me
    git简洁命令列表
    自定义控件(3)
    自定义控件(2)
    自定义控件(1)- 标签页
    使用AppleScript实现一个批量添加文件前缀的功能
    Win10下Wifi不能自动连接的问题
    Android利用Ksoap2调用Webservice时接收参数为空的问题
  • 原文地址:https://www.cnblogs.com/selfimprove/p/3162552.html
Copyright © 2011-2022 走看看