1

以下查询是我以前使用的查询...但我想将这两个查询结合起来以提高性能

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')
)

如何结合两个查询并一次获取计数和值?

4

2 回答 2

0

试试这个:

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;
于 2012-10-15T13:09:37.613 回答
0
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
于 2012-10-15T13:09:49.117 回答