也许它太明显了,但我确信它必须是一种简单的方法来做到这一点
SELECT 'Not Contained Yet' AS FlagRow
FROM (
SELECT 'Already Contained'
FROM MyTable t
WHERE t.id=?
AND CURDATE()=t.date
LIMIT 1
) aux
HAVING COUNT(*)=0
如果寄存器已经在数据库中(通过id,日期),那么只返回没有结果,并返回一行,其中包含消息' Not Contained Yet'如果它不存在。
如何在不使用子选择的情况下查询该特殊性?我只需要一个带有乱码的行,因为它可以作为启动我的ETL的触发器,以防当天没有条目和id
答案 0 :(得分:1)
如果count()
不包含记录
0
SELECT count(*) as contains_count
FROM MyTable t
WHERE t.id = ?
AND DATE(NOW()) = t.date
答案 1 :(得分:1)
您应该可以使用having
:
SELECT 'Not Contained Yet' AS FlagRow
FROM MyTable t
WHERE t.id = ? and CURDATE()=t.date
HAVING COUNT(*) = 0;
答案 2 :(得分:1)
SELECT CASE WHEN count(*) = 0 THEN 'Not Contained Yet' ELSE null END CASE
FROM MyTable t
WHERE t.id=?
AND CURDATE()=t.date