select count(case when tuple.qcount > 0 then 1 else null...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

select

  count(case when tuple.qcount > 0 then 1 else null end),
  count(case when tuple.acount > 0 then 1 else null end)
  
  from (
    select users.id, users.displayname,
      count(case when posts.posttypeid = 1 then 1 else null end) as qcount,
      count(case when posts.posttypeid = 2 then 1 else null end) as acount
      from users, posts
      where users.id = posts.owneruserid and users.location = 'Russia'
      group by users.id, users.location, users.displayname
      having
        count(case when posts.posttypeid = 2 then 1 else null end) > 0
        and count(case when posts.posttypeid = 1 then 1 else null end) = 0 or
        count(case when posts.posttypeid = 1 then 1 else null end) > 0
        and count(case when posts.posttypeid = 2 then 1 else null end) = 0) as tuple

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results