Skip to content

Commit 1e8cd34

Browse files
committed
Add SQL query examples
1 parent 2f00eb6 commit 1e8cd34

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ Here is an Entity Relationship Diagram (ERD) of the database structure.
8181

8282
![Entity Relationship Diagram (ERD) of the database structure](images/patents_view_table.png)
8383

84-
## Selecting Patents
84+
## Using SQL to Select Patents
8585

86-
Use the following to select patents between two dates:
86+
The `sql` folder has some SQL scripts that might come in handy.
87+
As an example, here is SQL query that selects patents between two dates:
8788

8889
```
8990
SELECT
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Use this script to find which cited patents need to be added to the Patents table.
3+
*/
4+
SELECT
5+
cited_patent_number
6+
FROM
7+
cited_patents
8+
WHERE
9+
cited_patent_number NOT IN (SELECT DISTINCT patent_number FROM patents);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Use this SQL query to select patents between two dates.
3+
* Uncomment the lines to retrieve the company ID and the alternate name ID.
4+
*/
5+
SELECT
6+
p.patent_number as "Patent Number",
7+
p.patent_title as "Patent Title",
8+
-- p.company_id as "Company ID",
9+
c.name as "Company Name",
10+
-- p.company_alternate_name_id as "Alternate Name ID",
11+
an.name as "Company Name Listed on Patent",
12+
p.year,
13+
p.grant_date as "Grant Date",
14+
p.uspc_class as "USPC Classes"
15+
FROM
16+
patents as p
17+
JOIN
18+
companies as c
19+
ON
20+
p.company_id = c.id
21+
LEFT JOIN
22+
alternate_company_names as an
23+
ON
24+
p.company_alternate_name_id = an.id
25+
WHERE
26+
p.grant_date > DATE("2006-01-03") AND
27+
p.grant_date < DATE("2010-06-13");

0 commit comments

Comments
 (0)