--創(chuàng)建數(shù)據(jù)庫
create database studentsDB
--創(chuàng)建表
create table student
(
?id int primary key,
?stuid char(10),
?stuname char(20),
?classname char(20),
?addresss char(40),
?cols int,
?sex char(10)
)
--更改數(shù)據(jù)項的數(shù)據(jù)類型
alter table student
alter column cols float
--插入數(shù)據(jù)
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,'男')
--查詢分?jǐn)?shù)在60-100的信息
select id,stuid,stuname,classname,addresss,cols,sex from student where cols between 60 and 100
--查詢班級里姓李的同學(xué)的信息
select id,stuid,stuname,classname,addresss,cols,sex from student where stuname like '李%'
--查詢分?jǐn)?shù)等于99和100的同學(xué)的信息
select id,stuid,stuname,classname,addresss,cols,sex from student where cols = 99 or cols =100
--根據(jù)分?jǐn)?shù)降序排列
select id,stuid,stuname,classname,addresss,cols,sex from student order by cols desc
--根據(jù)性別求出男生和女生分?jǐn)?shù)的平均值
select avg(cols) as 平均成績,sex from student group by sex
--求出各班的平均成績
select avg(cols) as 平均成績,classname from student group by classname
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
