USE test
DROP TABLE if EXISTS grade
create table `grade` (
`id` int PRIMARY KEY,
`name` varchar (300),
`score` double
)
insert into `grade` (`id`, `name`, `score`) values('1','n1','59')
insert into `grade` (`id`, `name`, `score`) values('2','n2','66')
insert into `grade` (`id`, `name`, `score`) values('3','n3','78')
insert into `grade` (`id`, `name`, `score`) values('4','n1','48')
insert into `grade` (`id`, `name`, `score`) values('5','n3','85')
insert into `grade` (`id`, `name`, `score`) values('6','n5','51')
insert into `grade` (`id`, `name`, `score`) values('7','n4','98')
insert into `grade` (`id`, `name`, `score`) values('8','n5','53')
insert into `grade` (`id`, `name`, `score`) values('9','n2','67')
insert into `grade` (`id`, `name`, `score`) values('10','n4','88')
首先将上面内容保存在一个名字叫grade.sql 的文件里面,上面我私自修改了id的类型,实在看不下去了。然后登陆数据库使用mysql>source C:/grade.sql;
select name,max(score) from grade
select name,sum(score) from grade group by name order by score desc limit 1,5
select name,sum(score) as tot from grade group by name having tot<150
select name,avg(score) as scavg from grade group by name having scavg <80 and scavg >60
select name from grade group by name having sum(score) >150 and avg(score) <90这个应该是查询人吧,6才是查询人数吧
亲测有效
假定你的字段名为 AMOUNT,那么在建立表时,可以这么写SQL语句CREATE TABLE YOUR_TABLE_NAME(
...
AMOUNT INT CHECK(AMOUNT<150),
...
)
如果表已建好,而要加上这个约束,那么可以这么SQL语句:
ALTER TABLE YOUR_TABLE_NAME ADD CHECK(AMOUNT<150)
祝你好运!
数据库查询数小于50应该怎么设置select
sum(case when 分数>60 then 1 else 0 end) as 大于60分,
sum(case when 分数<50 then 1 else 0 end) as 大于50分
from 表名
select '大于60分',count(*) from 表名 where 分数>60
union all
select '小于50分',count(*) from 表名 where 分数<50
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)