MYSQL基础查询语言试题,请大家帮我做一下,谢谢了! 200分!!

2025-01-27 14:27:25
推荐回答(3个)
回答1:

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;

  1.  select name,max(score) from grade;

  2.  select name,sum(score)  from grade group by name order by score desc limit 1,5;

  3. select name,sum(score) as tot from grade  group by name having tot<150;

  4. select name,avg(score) as scavg from grade group by name having scavg < 80 and scavg > 60 ;

  5. select name from grade group by name having sum(score) > 150 and avg(score) < 90;这个应该是查询人吧,6才是查询人数吧

    亲测有效

回答2:

你这数据库哪里体现两门功课了?

回答3:

select max(score) from grade
select sum(score) from grade group by name limit(2,4)
select sum(score) from grade group by name where sum(score) < 150
select name,avg(sum(score)) from grade group by name where avg(sum(score)) > 60 and avg(sum(score)) < 80
select name,avg(sum(score)) from grade group by name where avg(sum(score)) < 90 and sum(score) > 150
select count(*) from grade group by name where avg(sum(score)) < 90 and sum(score) > 150