Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

SQL

BASIC QUERIES
for non-developer
TOPICS
where A is NULL join A
Condition Multiple tables

select * group by A where ID in (select ID ... )


View selection Aggregation Subqueries
SELECTIONS
• SELECT * FROM episodes;
• SELECT TOP 10 * FROM episodes;
• SELECT partyId, partyIdentifierId FROM
episodes;
• SELECT DISTINCT Gender FROM episodes;
Tables
Episode Table Finding Table
Id PartyIdentifier DateOfBirth Genender Id EpisodeId FindingCode Value
Code

1 1 smoker yes
1 10101010101 1971-07-02 female
00:00:00.0000000

2 1 HbA1c 5.69
2 10101010102 2020-07-02 male
00:00:00.0000000

3 2 HbA1c 6
CONDITIONS
• SELECT * FROM episodes WHERE PartyIdentifierId =
'1010101010';
• SELECT * FROM episodes WHERE DateOfBirth IS
NULL;
• SELECT * FROM episodes WHERE DateOfBirth >
'1988-01-01' ORDER BY DateOfBirth DESC
AGGREGATIONS
SELECT episodeId, COUNT(*)
FROM findings f
LEFT JOIN episodes e ON e.Id = f.episodeId
WHERE genderCode= ‘female’
GROUP BY episodeId
HAVING COUNT(*) > 110 ;
MULTIPLE TABLES
SELECT *
FROM episodes e
LEFT JOIN findings f on e.Id = f.episodeId
WHERE PartyIdentifierId = '1010101010';
MULTIPLE TABLES
SELECT *
FROM episodes e
FULL JOIN findings f on e.Id = f.episodeId
WHERE PartyIdentifierId = '1010101010';
SUBQUIRIES
SELECT *
FROM findings
WHERE episodeId in (
SELECT Id
FROM episodes
WHERE genderCode = ‘female’)
Any questions?

You might also like