SELECT
*
FROM
MY_TABLE
CROSS JOIN
(
SELECT
COUNT(*) c
FROM
MY_TABLE
WHERE
COL_A = 1
AND
COL_B = 'mystring'
) MY_WHERE_COUNT
WHERE (
MY_WHERE_COUNT.c > 0 AND MY_TABLE.COL_A = 1 AND MY_TABLE.COL_B = 'mystring'
)
OR (
MY_WHERE_COUNT.c = 0 AND MY_TABLE.COL_A = 1
)
2条答案
按热度按时间lsmepo6l1#
如果没有太多的值
col_a
值,可以使用:只需使用结果集中的第一行。
liwlm1x92#
假设这是mssql: