sort by plus cards+solution+sql2

  select c.name, coalesce(count,0) as sort_field 
  from cards c
  left join (
    select z.id, count(*) as count
    from cards z
    join wiki_references r on r.referenced_card_id = z.id
    where r.card_id in (
      select id from cards tx                                            
      where tx.tag_id in
        (select id from cards txx where txx.key = 'territory') 
      and tx.trunk_id in 
        (select id from cards txx  where txx.extension_type = 'User')
    )
    group by z.id
  ) s                                                          
  on c.id = s.id
  where c.type='Zone' 
  and c.trash is false                    
  order by sort_field desc
  limit 10;

try it

 

wagneers

intro

videos

features

syntax

weekly calls

ideas

 

twitter

mailing list

 

developers

roadmap

next release

tickets

pack API

REST API

one-pager

 

github

mailing list

 

wagn.org

recent

todo