你好堆栈溢出社区。
我正在使用 SQL 从 PATSTAT(来自欧洲专利局的专利数据库)中检索数据。我有两个问题(见下文)。为了您的信息,PATSAT sql 命令非常有限。
一、具有多个值的Charindex
我正在寻找特定的两个特定专利组 ["Y02E" 和 "Y02C"],并希望检索这些专利组的数据。我发现如果我插入一组,使用 charindex 函数就可以了;
and charindex ('Y02E', cpc_class_symbol) > 0
但是如果我想使用另一个 charindex 函数,查询就会超时;
and charindex ('Y02E', cpc_class_symbol) > 0 or charindex ('Y02C', cpc_class_symbol) >0
我是一个绝对的 SQL 菜鸟,但非常感谢您的帮助!
二、用逗号分隔一个单元格中的列中的值
本质上,我想应用我发现的“string_agg”命令,但是,它不适用于这个数据库。我有具有唯一 ID 的条目,其中包含多个专利类别。例如:
appln_nr_epodoc | cpc_class_symbol
EP20110185794 | Y02E 10/125
EP20110185794 | Y02E 10/127
但是,我希望它是这样的:
appln_nr_epodoc | cpc_class_symbol
EP20110185794 | Y02E 10/125, Y02E 10/127
同样,我对 sql 很陌生,因此感谢您的帮助!谢谢!
我还将在此处附上完整的代码以提高透明度
SELECT a.appln_nr_epodoc, a.appln_nr_original, psn_name, person_ctry_code, person_name, person_address, appln_auth+appln_nr,
appln_filing_date, cpc_class_symbol
FROM
tls201_appln a
join tls207_pers_appln b on a.appln_id = b.appln_id
join tls206_person c on b.person_id = c.person_id
join tls801_country on c.person_ctry_code= tls801_country.ctry_code
join tls224_appln_cpc on a.appln_id = tls224_appln_cpc.appln_id
WHERE appln_auth = 'EP'
and appln_filing_year between 2005 and 2012
and eu_member = 'Y'
and granted = 'Y'
and psn_sector = 'company'
and charindex ('Y02E', cpc_class_symbol) > 0