SQL练习

2.1分组统计

按类型显示电影的数量、平均片长,最高票价,按票价、片长升序显示, 常规分组统计

select typeID 类型,count(*) 数量, avg(filmLength)  平均片长(分钟), max(ticketPrice)  最高票价   from movie group by typeID  order by ticketPrice,filmLength

按类型显示票价不高于 100 元的电影的数量、平均片长,最高票价,按票价、片长升序显示,分组之前进行过滤

select typeID 类型,count(*)  数量,  avg(filmLength)  平均片长(分钟), max(ticketPrice)  最高票价  from movie where ticketPrice <=100 group by typeID   order by ticketPrice,filmLength  

显示票价不高于 100 元的电影的数量、平均片长和最高票价,按票价片长升序显示平均片长不小于 100 分钟的统计信息,利用 having 子句对分组结果进行过滤

select typeID 类型,count(*)  数量,  avg(filmLength)  平均片长(分钟), max(ticketPrice)  最高票价  from movie where ticketPrice <=100 group by typeID  having avg(filmLength) >=100    order by ticketPrice,filmLength  having avg(filmLength) >=100  

2.2链接查询-内连接查询

 

posted @ 2021-02-24 10:34  二哈lulu  阅读(35)  评论(0编辑  收藏  举报