关于sql的问题..... [英] question about sql.....

查看:80
本文介绍了关于sql的问题.....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个查询来显示部门名称,部门名称以一个部门开头的所有部门的平均工资



  SELECT  depname,avg(薪水)
FROM 表1
WHERE depname 喜欢 ' a %'
GROUP BY depname;

< br $> b $ b



以上查询是对还是错?

解决方案

没关系。



您将获得以'a'开头的部门列表,其中包含该部门的平均工资。



但是,如果你想要所有部门的平均工资,那么不要包括 depname 而不要 group by

 选择 avg(薪水)来自 Table1 
其中 depname 喜欢 ' a%'


i write a query to display department name, average salary of all those departments whose department name start with a

SELECT depname, avg(salary)
FROM Table1
WHERE depname like 'a%'
GROUP BY depname;




is above query is right or wrong?

解决方案

It's fine.

You will get a list of the departments beginning with 'a' with the average salary for that department.

However, if you wanted the average salary across all of the departments then don't include the depname and don't group by i.e.

select avg(salary) from Table1
where depname like 'a%'


这篇关于关于sql的问题.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆