Please assist to fix the query below:   use SQLBook; WITH oz as ( SELECT zc.zcta5, (COUNT(DISTINCT c.HouseholdId) / MAX(zc.tothhs*1.0) ) as penetration, zc.tothhs, zc.medianhhinc, zc.pctbachelorsormore), ozm as ( SELECT AVG(medianhhinc) as avgmedianhhinc, STDEV(medianhhinc) as stdmedianhhinc, AVG(pctbachelorsormore) as avgpctbachelorsormore, STDEV(pctbachelorsormore) as stdpctbachelorsormore FROM oz ), ozs as ( SELECT oz.*, ((oz.medianhhinc - ozm.avgmedianhhinc) / ozm.stdmedianhhinc ) as z_medianhhinc, ((oz.pctbachelorsormore - ozm.avgpctbachelorsormore) / ozm.stdpctbachelorsormore) as z_pctbachelorsormore FROM oz CROSS JOIN ozm ) SELECT TOP 10 ozs,*, SQRT(SQUARE(ozs.z_medianhhinc - ozs10021.z_medianhhinc) + SQUARE(ozs.z_pctbachelorsormore – ozs10021.z_pctbachelorsormore) ) as dist FROM ozs CROSS JOIN (SELECT ozs.* FROM ozs WHERE ozs.zcta5 = '10021') ozs10021 ORDER BY dist ASC

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

Please assist to fix the query below:

 

use SQLBook;

WITH oz as (
SELECT zc.zcta5,
(COUNT(DISTINCT c.HouseholdId) /
MAX(zc.tothhs*1.0) ) as penetration,
zc.tothhs, zc.medianhhinc, zc.pctbachelorsormore),
ozm as (
SELECT AVG(medianhhinc) as avgmedianhhinc,
STDEV(medianhhinc) as stdmedianhhinc,
AVG(pctbachelorsormore) as avgpctbachelorsormore,
STDEV(pctbachelorsormore) as stdpctbachelorsormore
FROM oz
),
ozs as (
SELECT oz.*,
((oz.medianhhinc - ozm.avgmedianhhinc) / ozm.stdmedianhhinc
) as z_medianhhinc,
((oz.pctbachelorsormore - ozm.avgpctbachelorsormore) /
ozm.stdpctbachelorsormore) as z_pctbachelorsormore
FROM oz CROSS JOIN ozm
)
SELECT TOP 10 ozs,*,
SQRT(SQUARE(ozs.z_medianhhinc - ozs10021.z_medianhhinc) +
SQUARE(ozs.z_pctbachelorsormore –
ozs10021.z_pctbachelorsormore)
) as dist
FROM ozs CROSS JOIN
(SELECT ozs.* FROM ozs WHERE ozs.zcta5 = '10021') ozs10021
ORDER BY dist ASC

1.sqi
(sa (59))
(sa (0)))
4 SELECT zc.zcta5,
5 (COUNT (DISTINCT C.HouseholdId) /
6 MAX (zc.tothhs*1.0) ) as penetration,
zc. tothhs, zc.medianhhinc, zc.pctbachelorsormore),
ozm as (
SELECT AVG(medianhhinc) as avgmedianhhinc,
10 STDEV (medianhhinc) as stdmedianhhinc,
11 AVG(pctbachelorsormore) as avgpctbachelorsormore,
STDEV(pctbachelorsormore) as stdpctbachelorsormore
7
9.
13
FROM oz
14 ),
15
ozs as (
16
SELECT oz.*,
17 ((oz.medianhhinc
18 )
ozm.avgmedianhhinc) / ozm.stdmedianhhinc
) as z_medianhhinc,
((oz.pctbachelorsormore - ozm.avgpctbachelorsormore) /
20 ozm.stdpctbachelorsormore) as z_pctbachelorsormore
FROM oz CROSS JOIN ozm
22)
SELECT TOP 10 ozs,
19
21
23
*
24 SQRT (SQUARE (ozs.z_medianhhinc - ozs10021.z_medianhhinc) +
SQUARE (ozs.z_pctbachelorsormore –
26 Fozs10021.z_pctbachelorsormore)
27) as dist
28
FROM ozs CROSS JOIN
29 E (SELECT ozs.* FROM ozs WHERE ozs.zcta5 = '10021') ozs10021
30
ORDER BY dist ASC
00 %
B Messages
Msg 102, Level 15, State 1, Line 23
Incorrect syntax near ','.
Msg 102, Level 15, State 1, Line 29
Incorrect syntax near 'ozs10021'.
Transcribed Image Text:1.sqi (sa (59)) (sa (0))) 4 SELECT zc.zcta5, 5 (COUNT (DISTINCT C.HouseholdId) / 6 MAX (zc.tothhs*1.0) ) as penetration, zc. tothhs, zc.medianhhinc, zc.pctbachelorsormore), ozm as ( SELECT AVG(medianhhinc) as avgmedianhhinc, 10 STDEV (medianhhinc) as stdmedianhhinc, 11 AVG(pctbachelorsormore) as avgpctbachelorsormore, STDEV(pctbachelorsormore) as stdpctbachelorsormore 7 9. 13 FROM oz 14 ), 15 ozs as ( 16 SELECT oz.*, 17 ((oz.medianhhinc 18 ) ozm.avgmedianhhinc) / ozm.stdmedianhhinc ) as z_medianhhinc, ((oz.pctbachelorsormore - ozm.avgpctbachelorsormore) / 20 ozm.stdpctbachelorsormore) as z_pctbachelorsormore FROM oz CROSS JOIN ozm 22) SELECT TOP 10 ozs, 19 21 23 * 24 SQRT (SQUARE (ozs.z_medianhhinc - ozs10021.z_medianhhinc) + SQUARE (ozs.z_pctbachelorsormore – 26 Fozs10021.z_pctbachelorsormore) 27) as dist 28 FROM ozs CROSS JOIN 29 E (SELECT ozs.* FROM ozs WHERE ozs.zcta5 = '10021') ozs10021 30 ORDER BY dist ASC 00 % B Messages Msg 102, Level 15, State 1, Line 23 Incorrect syntax near ','. Msg 102, Level 15, State 1, Line 29 Incorrect syntax near 'ozs10021'.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Query Syntax
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education