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
質問する
88 次
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 に答える