有人能告诉我这个查询有什么问题 [英] Can someone tell me what's wrong with this query

查看:100
本文介绍了有人能告诉我这个查询有什么问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要部门名称和最高激励价值,而以下查询返回所有部门和所有奖励。有人可以帮忙吗?



我尝试了什么:



选择部门,(从tbl_INCENTIVES中选择ISNULL(max(INCENTIVE_AMOUNT),0)

)作为max_incentive

来自tbl_Employee

解决方案

< blockquote>

选择Top 1部门,max(incentive_amount)作为incentive_amount 
来自tbl_employee
内部联接tbl_incentives on employee_id = employee_ref_id
按部门分组


 选择  TOP  < span class =code-digit> 1  department,max(incentive_amount) as  incentive_amount 
来自 tbl_employee
内部 join tbl_incentives on employee_id = employee_ref_id
部门
订单 max(incentive_amount) DESC


I want the department name and the highest incentive value, whereas the below query returns all the departments and all the incentives. Can someone help?

What I have tried:

select Department, (select ISNULL(max(INCENTIVE_AMOUNT),0)
from tbl_INCENTIVES) as max_incentive
from tbl_Employee

解决方案

select Top 1 department, max(incentive_amount) as incentive_amount  
from tbl_employee
inner join tbl_incentives on employee_id = employee_ref_id
Group by department


select TOP 1 department, max(incentive_amount) as incentive_amount 
from tbl_employee
inner join tbl_incentives on employee_id = employee_ref_id
Group by department
Order by  max(incentive_amount) DESC


这篇关于有人能告诉我这个查询有什么问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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