代码之家  ›  专栏  ›  技术社区  ›  user3871

计算表中缺少的值

  •  0
  • user3871  · 技术社区  · 6 年前

    在PostgreSQL中,如何从表中选择缺少的值?

    :一个 string a 有类型 Battle 没有类型 Activity ,其中有许多实例 字符串a .

    见下图。对于下面的查询,我查询了type 战斗 活动 以及在中突出显示的行 红色 蓝色 是类型的行 战斗 我需要知道的是不是在打字 活动 .

    问题 :那么从这个例子中,如何返回类型中不存在的所有6行 ?

    enter image description here

    问题是:

    select count(vocab_id), vocab_match, player_response, player_response_target, response_id
    from (
        select v.id as vocab_id, vocabulary as vocab_match, sq.id as response_id, sq.amatch as response_match, sq.player_response, sq.player_response_target, sq.dialog, sq.dialog_target
        from vocabulary_es v
        right join (
            select trim((regexp_matches(a.player_response_target, '\[t-(.*?)\]', 'g'))[1]) as amatch, a.id, a.player_response, a.player_response_target, a.dialog, a.dialog_target, a.event_type
            from (
                select drena.event_type, r.id, r.player_response, r.player_response_target, d.dialog, d.dialog_target
                from dialogresponses dr
                left join responses r on (r.id = dr.response_id)
                left join dialogs d on (d.id = dr.dialog_id)
                left join dialogresponses_eventsnpcs_all drena on (drena.dialogresponse_id = dr.id)
                where dr.locale_id = 1
                and dr.response_id IS NOT NULL
                and drena.event_type = 'Battle'
            ) as a
    
            order by a.id asc
        ) as sq
        on (trim(v.vocabulary) ilike trim(sq.amatch))
        where v.vocabulary IS NOT NULL
    
    ) as final
    group by vocab_id, vocab_match, player_response, player_response_target, response_id
    order by response_id asc;
    
    0 回复  |  直到 6 年前