10)-MySQL数据库基础练习(答案版)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了10)-MySQL数据库基础练习(答案版),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5717字,纯文字阅读大概需要9分钟。
内容图文
![10)-MySQL数据库基础练习(答案版)](/upload/InfoBanner/zyjiaocheng/504/941efd60d3274fe08b0351d57755bf6b.jpg)
只用于单个列 AVG()只能用来确定特定数值列的平均值,而且列名必须作为函数参数给出。为了获得多个列的平均值,必须使用多个AVG()函数。28补充://去重后,进行某列平均值计算 #去重计算平均值 select avg(distinct sname) from student; 29://返回某列的行数 #聚合函数:返回某列行数 select count(sname) from student; 30://返回列表中所有的行数 #聚合函数:返回所有行数 select count(*) from student; 31://返回某列的最大值 #聚合函数:返回列中最大值 select max(sname) from student; 32://返回某列的最小值 #聚合函数:返回列中最小值 select min(sname) from student; 33://返回某列值得和 #聚合函数:返回列值的和 select sum(sname) from student; 34://组合使用聚合函数 #聚合函数组合使用 select count(*) as count_number, avg(number) as avg_number, max(number) as max_number, min(number) as min_number, sum(number) as sum_number from score; 35://分组查询 select vend_id, count(*) as num_prods from products group by vend_id; 36://分组查询,增加查询条件 select cust_id, count(*) as orders from orders group by cust_id having count(*) >= 2; 目前为止所学过的所有类型的where子句都可以用having来替代。唯一的差别是where过滤行,而having过滤分组。 这里有另一种理解方法,where在数据分组前进行过滤,having在数据分组后进行过滤。这是一个重要的区别,where排除的行不包括在分组中。 37://分组排序 select order_num, sum(quantity*item_price) as ordertotal from orderitems group by order_num having sum(quantity*item_price) >= 50 order by ordertotal; 38://子查询 select cust_name, cust_contact from customers where cust_id in (select cust_id from orders where order_num in (select order_num from orderitems where prod_id = ‘tnt2‘)); 可以把一条select语句返回的结果用于另一条select语句的where子句。 39://多表联合查询及创建联结 select vend_name, prod_name, prod_price from vendors, products where vendors.vend_id = products.vend_id order by vend_name, prod_name; SELECT语句与前面所有语句一样指定要检索的列。这里,最大的差别是所指定的两个列(prod_name和prod_price)在一个表中,而另一个列(vend_name)在另一个表中。 现在来看FROM子句。与以前的SELECT语句不一样,这条语句的FROM子句列出了两个表,分别是vendors和products。它们就是这条SELECT语句联结的两个表的名字。这两个表用WHERE子句正确联结,WHERE子句指示MySQL匹配vendors表中的vend_id和products表中的vend_id。 可以看到要匹配的两个列以vendors.vend_id和products.vend_id指定。这里需要这种完全限定列名,因为如果只给出vend_id,则MySQL不知道指的是哪一个(它们有两个,每个表中一个)。 40://联合多个表查询 select prod_name, vend_name, prod_price, quantity from orderitems, products, vendors where products.vend_id = vendors.vend_id and orderitems.prod_id = products.prod_id and order_num = 20005;
10)-MySQL数据库基础练习(答案版)
标签:返回 prim 最小值 组合 指示 font 数组 名称 core
本文系统来源:https://www.cnblogs.com/shsm/p/10118191.html
内容总结
以上是互联网集市为您收集整理的10)-MySQL数据库基础练习(答案版)全部内容,希望文章能够帮你解决10)-MySQL数据库基础练习(答案版)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。