sql语句面经手撕(定制整理版)

一张表 店铺id 商品id 销售数量 问:查询总销售数量最多的店铺

SELECT 
    shop_id,
    SUM(quantity) AS total_quantity
FROM 
    sales
GROUP BY 
    shop_id
ORDER BY 
    total_quantity DESC
LIMIT 1;

学生总分名最高的

SELECT 
    student_id,
    SUM(score) AS total_score
FROM 
    scores
GROUP BY 
    student_id
ORDER BY 
    total_score DESC
LIMIT 1;

输出年龄大于20的学生年龄;更新表内所有年龄从18到20

只记得查询部分,面试官提了要用update set,但怕说错语法

SELECT age FROM students WHERE age > 20;


UPDATE students SET age = 20 WHERE age = 18;

a表里学生id, name,b表学生id, record,要求查询id, name, record并且按照id降序排列

SELECT 
    a.id, 
    a.name, 
    b.record
FROM 
    a
JOIN 
    b ON a.id = b.id
ORDER BY 
    a.id DESC;
学生表 student
id name chinese  math     english
1  john  90       80       70
2  tom   100      85       90
3  lily  80       70       70
4  jerry 90       60       60


1、按语文分数排序
select * from student order by chinese
2、求数学成绩的和
select sum(math) from student

你可能感兴趣的:(数据库,sql)