problems with "group by" in my query
Posted: Wed May 10, 2017 1:32 pm
Hello,
i have two questions regarding the "group by" command. (patstat 2016b)
1. May anyone outline what is neccessary to make a query with a "group by" command run successfully?
2. Maybe you could help me with my specific query directly:
In the following query I would like to summarize every result with the same appl id in a single row. Therefore I think I need the group by key. Thank you in advance and kind regards.
select DISTINCT a.appln_id,a.appln_auth, IPR_type, granted, docdb_family_id, nb_applicants, more1.number_applt as Anzahl_Unternehmen,
nb_inventors, publn_kind, publn_date, c.person_id, d.person_id, psn_sector, psn_name, d.person_ctry_code, e.ctry_code, e.epo_member
From tls201_appln as a
join tls211_pat_publn as b on a.appln_id=b.appln_id
join tls207_pers_appln as c on a.appln_id=c.appln_id
join tls206_person as d on c.person_id=d.person_id
join tls801_country as e on a.appln_auth=e.ctry_code
join (
select appln_id, count (applt_seq_nr) number_applt
from tls207_pers_appln
join tls206_person on tls207_pers_appln.person_id = tls206_person.person_id
where applt_seq_nr > 0 and invt_seq_nr = 0 and psn_sector in ('COMPANY',
'COMPANY GOV NON-PROFIT',
'COMPANY GOV NON-PROFIT UNIVERSITY',
'COMPANY HOSPITAL',
'COMPANY UNIVERSITY',
'GOV NON-PROFIT',
'GOV NON-PROFIT HOSPITAL',
'GOV NON-PROFIT UNIVERSITY',
'HOSPITAL',
'UNIVERSITY',
'UNIVERSITY HOSPITAL')
group by appln_id
having count(applt_seq_nr)>=2) as more1 on a.appln_id = more1.appln_id
where
ipr_type = 'PI'
and publn_date between '2015-01-01' and '2016-06-30'
and (epo_member = 'Y' or appln_auth = 'EP')
and more1.number_applt >= 2
and psn_sector in ('COMPANY',
'COMPANY GOV NON-PROFIT',
'COMPANY GOV NON-PROFIT UNIVERSITY',
'COMPANY HOSPITAL',
'COMPANY UNIVERSITY',
'GOV NON-PROFIT',
'GOV NON-PROFIT HOSPITAL',
'GOV NON-PROFIT UNIVERSITY',
'HOSPITAL',
'UNIVERSITY',
'UNIVERSITY HOSPITAL')
Order by a.docdb_family_id, a.appln_auth, b.publn_kind desc
i have two questions regarding the "group by" command. (patstat 2016b)
1. May anyone outline what is neccessary to make a query with a "group by" command run successfully?
2. Maybe you could help me with my specific query directly:
In the following query I would like to summarize every result with the same appl id in a single row. Therefore I think I need the group by key. Thank you in advance and kind regards.
select DISTINCT a.appln_id,a.appln_auth, IPR_type, granted, docdb_family_id, nb_applicants, more1.number_applt as Anzahl_Unternehmen,
nb_inventors, publn_kind, publn_date, c.person_id, d.person_id, psn_sector, psn_name, d.person_ctry_code, e.ctry_code, e.epo_member
From tls201_appln as a
join tls211_pat_publn as b on a.appln_id=b.appln_id
join tls207_pers_appln as c on a.appln_id=c.appln_id
join tls206_person as d on c.person_id=d.person_id
join tls801_country as e on a.appln_auth=e.ctry_code
join (
select appln_id, count (applt_seq_nr) number_applt
from tls207_pers_appln
join tls206_person on tls207_pers_appln.person_id = tls206_person.person_id
where applt_seq_nr > 0 and invt_seq_nr = 0 and psn_sector in ('COMPANY',
'COMPANY GOV NON-PROFIT',
'COMPANY GOV NON-PROFIT UNIVERSITY',
'COMPANY HOSPITAL',
'COMPANY UNIVERSITY',
'GOV NON-PROFIT',
'GOV NON-PROFIT HOSPITAL',
'GOV NON-PROFIT UNIVERSITY',
'HOSPITAL',
'UNIVERSITY',
'UNIVERSITY HOSPITAL')
group by appln_id
having count(applt_seq_nr)>=2) as more1 on a.appln_id = more1.appln_id
where
ipr_type = 'PI'
and publn_date between '2015-01-01' and '2016-06-30'
and (epo_member = 'Y' or appln_auth = 'EP')
and more1.number_applt >= 2
and psn_sector in ('COMPANY',
'COMPANY GOV NON-PROFIT',
'COMPANY GOV NON-PROFIT UNIVERSITY',
'COMPANY HOSPITAL',
'COMPANY UNIVERSITY',
'GOV NON-PROFIT',
'GOV NON-PROFIT HOSPITAL',
'GOV NON-PROFIT UNIVERSITY',
'HOSPITAL',
'UNIVERSITY',
'UNIVERSITY HOSPITAL')
Order by a.docdb_family_id, a.appln_auth, b.publn_kind desc