mysql作业-牛客

1

mysql作业-牛客_第1张图片
这个题已经为咱创建了表,所以直接输出就行。

select * from user_profile;

2

mysql作业-牛客_第2张图片
查询多列,在select 后加上对应的列名即可

select device_id,gender,age,university from user_profile;

3.

mysql作业-牛客_第3张图片
查询结果要求去重,在select 后加上distinct 再加上对应的列名

select distinct university from user_profile;

4.

select device_id from user_profile where id<=2;
select device_id as user_infos_example from user_profile where id<=2;
select device_id,university from user_profile where university='北京大学';
select device_id,gender,age,university from user_profile where age>24;
select device_id,gender,age from user_profile where age>=20 and age<=23;
select device_id,gender,age,university from user_profile where university != '复旦大学';
select device_id,gender,age,university from user_profile where age is not null;
select device_id,gender,age,university,gpa from user_profile   where gender='male' and gpa>3.5;
select device_id,gender,age,university,gpa from user_profile where university='北京大学' or gpa>3.7;
select device_id,gender,age,university,gpa from user_profile where university='北京大学' || university='复旦大学' || university='山东大学';
select device_id,gender,age,university,gpa from user_profile where (gpa>3.5 and university='山东大学') or (gpa>3.8 and university = '复旦大学');
select device_id,age,university from user_profile where university like '北京%';

36.

mysql作业-牛客_第4张图片

select device_id,age from user_profile order by age;

37.

mysql作业-牛客_第5张图片
要求先按照gpa升序排序,再按照年龄升序排序输出
所以order by 后 的顺序为gpa,age(默认为升序排序,所以不用加desc)

select device_id,gpa,age from user_profile order by gpa,age;

mysql作业-牛客_第6张图片
本题要求降序排序,和37 题的区别是在gpa 和 gpa 的后面加desc(desc的作用就是降序)

select device_id,gpa,age from user_profile order by gpa desc,age desc;

你可能感兴趣的:(MySQL,mysql,数据库,MySQL作业)