SQL QuestSQL Interview Questions › Subqueries & CTEs

Active Properties with Permits

HardProQuerying BasicsSubqueries & CTEsJoinsAggregation & Grouping

Find properties with 2 or more issued permits. Use a CTE that groups permits by bbl + counts. JOIN to properties for borough + address + assess_total. Show bbl, address, borough, assess_total, permit_count. Order by permit_count descending, then assess_total descending. Top 15.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

properties

bblboroughaddresszipbldg_classland_useyear_builtnum_floorsunits_residentialunits_totallot_area_sqftbldg_area_sqftassess_totalowner_namelatitudelongitude
1009720001MN240 1 AVENUE10009D74194513.00000008764881226750008942176790924050.00000BPP ST OWNER LLC40.7317236-73.9778964
1009950005MN1472 BROADWAY10036O45199851.000000002458001642675489648150.00000NYC ECONOMIC DEVELOPMENT CORPORATION40.7560214-73.9857642
1010070029MN1345 AVENUE OF THE AMER10105O95196849.0000000050903751931978429758550.000001345 LEASEHOLD LLC40.7630634-73.9792541

permits

permit_idjob_idbblboroughpermit_typepermit_statuswork_typefiling_dateissuance_dateexpiration_datebldg_typeowner_business_nameowner_business_typepermittee_business_name
16884114017497564006730016QUEENSSGISSUEDNULL01/08/200401/08/200406/30/20042HIGH PERFORMANCE FITNESS CENTERPARTNERSHIPPAUL SIGNS INC
17567813018206613026080079BROOKLYNEWISSUEDMH09/02/200409/10/200409/10/20052NULL2022-05-09 00:00:00APEX REALTY CO. LLC 7183915300 O
31364022132894095540029QUEENSSGISSUEDNULL01/30/200604/11/200606/30/20062Doral Bank: 7188507290 2022INDIVIDUALWNITECH DESIGN INC DBA SPACESIGN

Expected output: BBLs with the most ISSUED permits

Hint

This is a Pro challenge — the hint, the step-by-step tutor and the reference solution open in the app.

Concepts

SELECT CTE JOIN GROUP BY Subquery Multi-CTE

Practise the topic: SQL practice questions · CTE practice · JOIN practice · GROUP BY exercises · Advanced SQL interview questions

Related questions

Cumulative Distinct Customers Over TimeHard · FreeRunning Total RevenueHard · FreeYear-over-Year GrowthHard · Free7-Day Rolling Revenue AverageHard · FreeMulti-CTE Revenue PipelineHard · FreeWealthy Survivor ProfileHard · Pro

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test