在where子句中聚合函数

在where子句中聚合函数

本文介绍了在where子句中聚合函数.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表A和B.我想要表A中的所有记录,其中
Sum(A.Duration)!= Sum(B.Duration)and A.Ecode = B.ECode.我正在尝试编写查询,但无法在where子句中使用聚合函数.
表A具有与列相同的Ecode,Ename,Duration,表B也具有相同的列名称.

请帮助我,谢谢.

I have two tables A and B. I want all the records from table A where
Sum(A.Duration)!=Sum(B.Duration)and A.Ecode=B.ECode.I am trying to write the query but getting that cant use aggregate function in where clause.
Table A have Ecode,Ename,Duration as Columns and Table B also have the same column name.

Please help me and thanks in advance.

推荐答案

SUM(A.Duration)

将在表A Duration列中添加所有记录,

will add all the records in the table A Duration column,

SUM(B.Duration)

将对表B执行相同操作

因此,要么获取所有记录(如果总数相同),要么不获取所有记录(如果总数不同)

无论哪种方式,您的查询都有点愚蠢,而且我不敢相信那是您真正想要做的.

will do the same for table B

So either you should get all the records (if the totals are the same) or none of them (if the totals are different)

Either way, your query is a little silly, and I can''t believe that is what you actually wanted to do.


Sum(A.Duration)!=Sum(B.Duration)



只需使用子查询即可.



Just use subqueries..

(select sum(duration) from tableA) != (select sum(duration) from tableB)



最好..



all the best..


Select * from TablaA A, TableB B
Where A.Ecode=B.ECode
group by ............ having Sum(A.Duration)!=Sum(B.Duration)


这篇关于在where子句中聚合函数.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-21 00:34