以下是示例查询
Select * from tb.Users u where u.Approved = 1 and u.userID IN ( SELECT us.UserID us FROM tb.UserStatementes us WHERE us.LogDate between date1 and date2 )
我需要选择IN子句中的所有用户,但是如果子查询没有返回记录,我需要选择所有用户(即忽略IN子句)
Select * from tb.Users u where u.Approved = 1 and ( u.userID IN ( SELECT us.UserID us FROM tb.UserStatementes us WHERE us.LogDate between date1 and date2 ) or not exists ( select 1 from tb.UserStatementes us where us.LogDate between date1 and date2 ) )