Mysql 如何从两个不同的表中获取两个不同的列值?一个值表依赖于另一个表值
以下查询是我以前使用的查询。。。但是我想结合这两个查询来提高性能Mysql 如何从两个不同的表中获取两个不同的列值?一个值表依赖于另一个表值,mysql,Mysql,以下查询是我以前使用的查询。。。但是我想结合这两个查询来提高性能 select a, b, c from table1 where d LIKE 'xxx' and f like 'yyyy' order by b desc; 我正在执行上述查询并读取值 对于上面查询中的每个b值,再次在循环中执行下面的查询 select count(*) from table2 where b=? AND js_email_id IN ( select js_email_id
select a, b, c
from table1
where d LIKE 'xxx'
and f like 'yyyy'
order by b desc;
我正在执行上述查询并读取值
对于上面查询中的每个b值,再次在循环中执行下面的查询
select count(*)
from table2 where b=? AND js_email_id IN
(
select js_email_id
from js_initialsignup
where UCase(jsaccountstatus) LIKE UCase('live')
AND UCase(js_status) LIKEUCase('accepted')
)
如何组合两个查询并一次获取计数和值?尝试以下方法:
SELECT t1.a, t1.b, t1.c, COUNT(t2.*)
FROM table1 t1
INNER JOIN table2 t2 ON t1.b = t2.b
INNER JOIN js_initialsignup j ON t2.js_email_id = j.js_email_id
WHERE t1.d LIKE 'xxx'
AND t1.f like 'yyyy'
AND UCase(j.jsaccountstatus) LIKE UCase('live')
AND UCase(j.js_status) LIKE UCase('accepted'))"
GROUP BY t1.a, t1.b, t1.c
ORDER BY by t1.b DESC;
有可能从上面的mysqlNo查询中获取行号吗?没有,但您有其他选项,但这与此查询有什么关系?从所有记录中,我每次只需要获取有限的记录
select a,b,c,
(select count(*)
from table2 where b=a.b AND js_email_id IN
(
select js_email_id
from js_initialsignup
where UCase(jsaccountstatus) LIKE UCase('live')
AND UCase(js_status) LIKEUCase('accepted')
)) as cnt
from table1 a