mysql从表a中选择,其中条件x和子选择

mysql从表a中选择,其中条件x和子选择,mysql,select,Mysql,Select,我想将表A中的注册数量计算为表B中确定的特定时间量 我正在寻找这样做的正确方法: SELECT count(*) as total from table_a as a WHERE a.created >= '0000-00-00 00:00:00' AND a.created <= (SELECT table_b.end WHERE table_b.id = 13) 选择count(*)作为总计 从表a作为 其中a.created>=“0000-00-00:00:00” 和a.cr

我想将表A中的注册数量计算为表B中确定的特定时间量

我正在寻找这样做的正确方法:

SELECT count(*) as total
from table_a as a
WHERE a.created >= '0000-00-00 00:00:00'
AND a.created <= (SELECT table_b.end WHERE table_b.id = 13)
选择count(*)作为总计
从表a作为
其中a.created>=“0000-00-00:00:00”
和a.created
选择count(*)作为总计
从表a作为
其中a.created>=“0000-00-00:00:00”

a.created您可以执行典型的连接:

SELECT COUNT(*) AS total
FROM table_a AS a 
JOIN table_b as b ON (a.created >= '0000-00-00 00:00:00' and a.created <= b.`end`)
WHERE b.id=13;
选择COUNT(*)作为总计
从表a作为

将表b连接为(a.created>='0000-00-00 00:00:00'和a.created='start`和a.created,以防有人需要,这是正确的方法:

SELECT count(*) as total
from table_a as a
WHERE a.created >= '0000-00-00 00:00:00'
AND a.created <= (SELECT table_b.`end` FROM table_b WHERE table_b.`id`=13)
选择count(*)作为总计
从表a作为
其中a.created>=“0000-00-00:00:00”

a.created您可以使用BETWEEN子句来实现这一点

SELECT count(*) as total
from table_a a
WHERE a.created BETWEEN '0000-00-00 00:00:00'
AND (SELECT table_b.`end` FROM table_b WHERE table_b.`id`=13)

您错过了第二个select查询中的From子句…谢谢!我没想到会如此接近解决方案!嗯,这是一种方法。不确定这是正确的方法!
SELECT count(*) as total
from table_a as a
WHERE a.created >= '0000-00-00 00:00:00'
AND a.created <= (SELECT table_b.`end` FROM table_b WHERE table_b.`id`=13)
SELECT count(*) as total
from table_a a
WHERE a.created BETWEEN '0000-00-00 00:00:00'
AND (SELECT table_b.`end` FROM table_b WHERE table_b.`id`=13)