<aside> 💡 In this project, I’ve developed a series of SQL queries to analyze data related to dog ownership and subscriptions. Starting with basic queries such as listing dogs alphabetically, I progressed to more detailed queries—counting dogs per owner, calculating total subscription costs, and examining all subscriptions, active or not. The final query highlights subscriptions with multiple dogs, reflecting my growing proficiency in SQL and data analysis for pet-related data.

</aside>

<aside> 📌 Each Queries gets more and more Complex

</aside>

Screenshot 2024-08-18 at 4.47.49 PM.png

Table of content:

SQL Query 1: List Dogs Alphabetically by Name

SELECT "Name" AS "DogName" FROM "DOGS" ORDER BY "DogName" ASC
DogName
Boots
Duke
Junebug
Spot

SQL Query 2: List Owners and Count of Dogs for each Owner, Order by Count of Dogs

SELECT "OWNERS"."Name" AS "OwnerName", COUNT( * ) AS "DogCount" 
FROM "DOGS", "OWNERS”
WHERE "DOGS"."Owner" = "OWNERS"."RowID" 
GROUP BY "OWNERS"."RowID", "OwnerName" 
ORDER BY "DogCount" ASC
OwnerName DogCount
Coco 1
Bai 1
Molokai 2

SQL Query 3: List Owner and Total Subscription Price for Active Subscriptions

SELECT "OWNERS"."Name" AS "Owner", SUM( "PLANS"."Cost" ) AS "Total Cost”
FROM "DOGS", "OWNERS", "SUBSCRIPTIONS", "PLANS" 
WHERE "DOGS"."Owner" = "OWNERS"."RowID" AND "DOGS"."RowID" = "DOGS"."RowID" AND "SUBSCRIPTIONS"."Dog" = "DOGS"."RowID" AND "SUBSCRIPTIONS"."Plan" = "PLANS"."RowID" AND "SUBSCRIPTIONS"."Ended" IS NULL GROUP BY "OWNERS"."RowID", "OWNERS"."Name"
Owner Total Cost
Bai 99
Molokai 298

SQL Query 4: List Owner, Dog, and Subscription for all subscriptions (not just active)

SELECT "OWNERS"."Name" AS "Owner", SUM( "PLANS"."Cost" ) AS "Total Cost" 
FROM "DOGS", "OWNERS", "PLANS", "SUBSCRIPTIONS" 
WHERE "DOGS"."Owner" = "OWNERS"."RowID" AND "PLANS"."RowID" = "SUBSCRIPTIONS"."Plan" AND "SUBSCRIPTIONS"."Dog" = "DOGS"."RowID" 
GROUP BY "OWNERS"."Name", "OWNERS"."RowID"
Owner Total Cost
Bai 148
Molokai 495

SQL Query 5: List Subscriptions and Counts of Dogs per subscription, but only subscriptions that have more than one dog

For this Query I used LibreOffice Relationship Builder

SELECT "SUBSCRIPTIONS"."Plan" AS "Plan ID", "PLANS"."Level" AS "Plan Level", COUNT( "SUBSCRIPTIONS"."Dog" ) AS "Dog Count" 
FROM "SUBSCRIPTIONS", "PLANS" 
WHERE "SUBSCRIPTIONS"."Plan" = "PLANS"."RowID" 
GROUP BY "SUBSCRIPTIONS"."Plan", "PLANS"."Level" HAVING ( ( COUNT( "SUBSCRIPTIONS"."Dog" ) > 1 ) )