0
SELECT * FROM
    (
        SELECT  DISTINCT table.column, (select count(table1.column1) from table1
        where table1.column1 = tablecolumn)
        AS exp1, (select count(table1.column3) FROm table1  
        LEfT OUTER JOIN table  On table1.column1 = table.column2   
        WHeRE table.column = table1.column3 AND table1.column1 <= table2.column1 AND table.column = 23206) AS exp2
        FROM table1
        WHERE table1.column1 = something and .......
    ) expVys
    WHERE exp1 >= exp2 ORDER BY table1.name1 DESC
4

1 回答 1

1

您可以定义一个 CTE:

;WITH MyCTE AS
(
 SELECT  DISTINCT table.column, ((select count(table.column) from table
 where table.column = tablecolumn)) 
     AS exp1, ((select count(table.column3) FROm table  
     LEfT OUTER JOIN table  On table.column = table.column2   WHeRE table.column = table.column3 AND table.column <= column 
     AND table.column = 23206)) AS exp2
     FROM table
)

SELECT * 
FROM   MyCTE
WHERE  exp1 >= exp2

我不知道这对您的评论是否有帮助,但您可以将其全部包含在 SELECT 中:

SELECT *
FROM
(
 SELECT  DISTINCT table.column, ((select count(table.column) from table
 where table.column = tablecolumn)) 
     AS exp1, ((select count(table.column3) FROm table  
     LEfT OUTER JOIN table  On table.column = table.column2   WHeRE table.column = table.column3 AND table.column <= column 
     AND table.column = 23206)) AS exp2
     FROM table
) TableAlias
WHERE exp1 >= exp2
于 2013-10-02T09:03:19.353 回答