我正在尝试查找包含大于7且小于13.99的值的行数。 但是,以下查询始终返回0,这是不可能的。
任何人都可以在我的查询中看到问题吗?
SELECT COUNT(*) FROM lead_status AS ls
INNER JOIN leads AS l ON l.id = ls.lead_id
INNER JOIN contacts AS c ON c.lead_id = l.id
WHERE ls.discriminator = 'AUTO_POST' AND l.affiliate_id=1003
AND ls.winner =1 AND l.test =0 AND l.create_date BETWEEN '2011-10-03' AND '2011-10-17'
AND ls.amount >= 7 AND ls.amount <= 13.99;
答案 0 :(得分:1)
您的查询似乎很好。但是,为了确保首先删除查询中的所有过滤器,然后逐个添加它们,您将获得哪个过滤器导致计数为零。
答案 1 :(得分:1)
您没有发布架构,但可能需要将字符串日期转换为实际日期值:
...AND l.create_date BETWEEN STR_TO_DATE('2011-10-03', '%Y-%M-%d') AND
STR_TO_DATE('2011-10-17', '%Y-%M-%d')
答案 2 :(得分:1)
小编辑,一些格式和怀疑:
SELECT COUNT(*)
FROM lead_status ls
INNER JOIN leads l ON l.id = ls.lead_id -- ls.id .. l.lead_id ??
INNER JOIN contacts c ON c.lead_id = l.id
WHERE ls.discriminator = 'AUTO_POST'
AND ls.winner = 1
AND ls.amount >= 7
AND ls.amount < 14
AND l.affiliate_id = 1003
AND l.test = 0
AND l.create_date BETWEEN '2011-10-03' AND '2011-10-17';
您有ls.lead_id
和c.lead_id
,但l.id
。这似乎不一致。错字?
你写道:
大于7且小于13.99
您的代码说:
大于或等于7且小于或等于13.99
我把它改成了(我怀疑那是你真正想要的):
大于或等于7且小于14