|
Posted by Erland Sommarskog on 02/18/07 12:15
(solonzenetzis@sbzsystems.com) writes:
> select *
> from tableA, tableB
>
> where tableA.num=tableB.order
>
> and tableA.num in (
> select tableB.order, sum(tableB.ok) as s_ok from tableA, tableB
> where
> tableB.order=tableA.num
> and tableB.cust_no=4895
> and s_ok<5
> )
> ------------------------------------------------------------------
> but it is not possible
> Can anyone help me?
As given the subquery could be written as
select tableB.order, sum(tableB.ok) as s_ok from tableA, tableB
where
tableB.order=tableA.num
and tableB.cust_no=4895
GROUP BY tableB.order
HAVING SUM(tableB.ok) < 5
But something tells me that it should not be necessary to include noth
table twice in the whole query, and that you should use EXISTS instead.
But since I don't have the full picture I cannot suggest an alternative.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
[Back to original message]
|