sql - Subquery on outer query -


update: please @ second query, more representable example

i'd create query uses different subqueries each column. subqueries based on list obtained outer query.

for example: consider tablea table 30 columns , 5 million records

select a, b, c, (select count(a) values (r = 12 , u = 'to') or (r = 16 , u in ('tb', 'tu')) first, (select count(a) values (r = 16 , u = 'te') or (r = 76 , u in ('te', 'tg')) second, (select count(a) values (r = 564 , u = 'hg') or (r = 788 , u in ('vd', 'bf')) third, (select count(a) values (r = 383 , u = 'rt') or (r = 35 , u in ('gr', 'ez')) fourth tablea values 

i know query not execute since can't call values subqueries, there solution make query run fast?


in subqueries, i'd need join table, still possible use values, or have subquery on tablea again?


following query more representable example:

select col1, col2,  (select count(col3) tablea ta inner join tableb b on tl.taskid = b.col6 inner join tablec c on b.id = c.taskid c.resultcode = 1 , ta.col4 = a.col4 , ta.col5 = a.col5) executed,  (select count(col3) tablea ta inner join tableb b on tl.taskid = b.col6 inner join tablec c on b.id = c.taskid c.resultcode = 9 , ta.col4 = a.col4 , ta.col5 = a.col5) notexecuted  tablea group col1, col2, col4, col5 

select a, b, c,        sum(case when not null , b=12 1 else 0 end) first,        sum(case when not null , b=16 1 else 0 end) second,         sum(case when not null , b=82 1 else 0 end) third,        sum(case when not null , b=167 1 else 0 end) fourth     tablea             group a, b, c   

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -