← All projects
CASE STUDY / POSTGRESQL / HEALTH DATA

Before the patterns,
check the data.

A SQL analysis of skin cancer records: joining patient and lesion data, examining diagnosis patterns and documenting what the dataset can—and cannot—support.

1,088joined records
0unmatched lesion records
53.4%missing usable diameter pairs
01 / THE QUESTION

What does this sample show?

The project examined diagnosis patterns, patient demographics, environmental variables and lesion characteristics in a supplied course dataset. The first task was to establish a dependable joined dataset before comparing groups.

This was an analytical capstone using PostgreSQL 18 and pgAdmin. It did not diagnose patients or train a prediction model. The source database is not distributed in the public repository.

02 / THE WORKFLOW

Validate. Join. Summarise.

  1. Check the source tables. Compare patient, lesion and joined row counts; identify unmatched records and repeated identifiers.
  2. Create a temporary analytical view. Join the tables on patient_id while preserving the original source tables.
  3. Handle unavailable measurements. Treat zero-coded skin type and diameters as unavailable, pending confirmation of their original meaning.
  4. Describe the sample. Use aggregations, CTEs, window functions and filtered counts to examine diagnoses and group proportions.
  5. Prepare traceable metadata. Retain identifiers for audit, while specifying their exclusion from future model predictors.
See the core join used in the project
SELECT p.patient_id, l.lesion_id,
       p.age, p.gender, l.diagnostic
FROM public.table1 AS p
JOIN public.table2 AS l
  ON l.patient_id = p.patient_id;

A shortened extract from the analytical workflow. The repository contains the complete script.

03 / DATA QUALITY

A clean join is only the beginning.

Validation results from the project report
CheckResult
Patient / lesion / joined rows1,088 / 1,088 / 1,088
Unmatched lesion records0
Repeated lesion ID values81, each appearing under two patients
Exact duplicate rows in the CSV0
Unavailable skin type after zero conversion579 records (53.2%)
Unavailable diameter pairs after zero conversion581 records (53.4%)

Repeated lesion IDs were not automatically deleted: the affected records belonged to different patients. The combined patient and lesion identifier was unique in the export, so it could support traceability while the original identifier convention remained unresolved.

The brief described 1,089 instances; the restored data and export contained 1,088. The reason for that difference was unconfirmed. All supplied records were retained.

Why this matters

Removing records solely because a lesion identifier repeats could discard distinct patient observations. Treating unavailable diameters as genuine zero measurements would distort lesion-size summaries.

04 / FINDINGS

Diagnosis patterns in 1,088 records.

ACK was the most frequent recorded diagnosis label. BCC, SCC and MEL together accounted for 346 records (31.8%). This combined category was used for descriptive comparisons, not as a newly validated diagnostic label.

Recorded diagnosis labels · number of records
ACK
461
BCC
273
NEV
144
SEK
137
SCC
56
MEL
17
View the diagnosis counts and percentages
Diagnosis distribution; denominator = 1,088
LabelRecordsShare
ACK46142.4%
BCC27325.1%
NEV14413.2%
SEK13712.6%
SCC565.1%
MEL171.6%

Age groups showed different proportions.

BCC/SCC/MEL grouping within each age band
Age bandAll recordsBCC/SCC/MELWithin-band share
Under 305723.5%
30–492214922.2%
50–6951317433.9%
70+29712140.7%

The proportion increased across the age bands in this dataset. These figures describe the supplied records; they do not estimate population incidence or an individual’s risk.

05 / INTERPRETATION

Useful patterns. Clear limits.

Measurement completeness differed substantially by diagnosis. Usable diameter pairs ranged from 14 of 137 SEK records to all 17 MEL records. Comparisons of lesion size could therefore reflect which records were measured as well as differences between groups.

The analysis was descriptive and unadjusted. Sampling, recruitment and the original label provenance were not established. Observed differences by age, symptoms or exposure do not establish causation or diagnostic accuracy. The other diagnosis labels should not all be grouped as “benign”.

Preparing a metadata export also does not make it ready for clinical modelling. Identifiers, biopsy status and related target labels require careful handling to avoid leakage.

06 / NEXT STEPS

Improve the evidence before extending the analysis.

  • Clarify the record-count discrepancy and lesion identifier convention with the provider.
  • Confirm the meaning of zero-coded values and investigate diagnosis-dependent missingness.
  • Verify label provenance before supervised modelling.
  • Use adjusted analysis and suitable independent data to investigate associations further.

What this project demonstrates

SQL joins and reusable views, explicit denominators, data-quality checks and cautious interpretation of health data. The central lesson is that reliable analysis depends on understanding the records before interpreting their patterns.

Project evidence

The findings above are drawn from the completed SQL capstone report and analytical script. The repository includes the report, queries, project context and instructions for running the supplied database.

CONTINUE THE CONVERSATION

Have a health data
question to explore?

Get in touch ↗