-
Notifications
You must be signed in to change notification settings - Fork 0
/
P3Queries.sql
89 lines (69 loc) · 2.7 KB
/
P3Queries.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
CSCI 585 HOMEWORK-3
NAME : AVINASH AKKA
USC ID: 3874-5774-01
--QUERIES--
*/
/*----------------------------QUERY A--------------------------*/
SELECT STUDENT.STUDENTID FROM STUDENT
WHERE sdo_filter(STUDENT.LOCATION,
SDO_geometry(2001,NULL,NULL,
SDO_elem_info_array(1,2003,3),
SDO_ordinate_array(200,200,300,300))
) = 'TRUE';
/*----------------------------QUERY B--------------------------*/
SELECT B.BUILDINGID AS BUILDNGIDS_TRAMSTPIDS_FRM_P1
FROM STUDENT S ,BUILDING B
WHERE S.STUDENTID = 'p1' AND
SDO_WITHIN_DISTANCE(B.SHAPE,S.LOCATION,'distance=300') = 'TRUE'
UNION ALL
SELECT T.TRAMSTOPID
FROM STUDENT S1,TRAMSTOP T
WHERE S1.STUDENTID = 'p1' AND
SDO_WITHIN_DISTANCE(T.COVERAGE,S1.LOCATION,'distance=300')= 'TRUE';
/*----------------------------QUERY C--------------------------*/
SELECT S.STUDENTID AS BUILDINGIDS_AND_STUDENTIDS
FROM STUDENT S,TRAMSTOP T
WHERE T.TRAMSTOPID = 't2ohe' AND SDO_WITHIN_DISTANCE(S.LOCATION,T.COVERAGE,'distance=300')='TRUE'
UNION
SELECT S.STUDENTID
FROM STUDENT S,TRAMSTOP T
WHERE T.TRAMSTOPID = 't5vhe' AND SDO_WITHIN_DISTANCE(S.LOCATION,T.COVERAGE,'distance=300')='TRUE'
UNION
SELECT S.STUDENTID
FROM STUDENT S,TRAMSTOP T
WHERE TRAMSTOPID = 't6ssl' AND SDO_WITHIN_DISTANCE(S.LOCATION,T.COVERAGE,'distance=300')='TRUE'
UNION
SELECT B.BUILDINGID
FROM TRAMSTOP T,BUILDING B
WHERE T.TRAMSTOPID = 't2ohe' AND SDO_WITHIN_DISTANCE(B.SHAPE,T.COVERAGE,'distance=300')='TRUE'
UNION
SELECT B.BUILDINGID
FROM BUILDING B,TRAMSTOP T
WHERE T.TRAMSTOPID = 't5vhe' AND SDO_WITHIN_DISTANCE(B.SHAPE,T.COVERAGE,'distance=300')='TRUE'
UNION
SELECT B.BUILDINGID
FROM BUILDING B,TRAMSTOP T
WHERE TRAMSTOPID = 't6ssl' AND SDO_WITHIN_DISTANCE(B.SHAPE,T.COVERAGE,'distance=300')='TRUE';
/*----------------------------QUERY D--------------------------*/
SELECT S1.STUDENTID, SDO_NN_DISTANCE(1) Distance
FROM STUDENT S1
WHERE SDO_NN(S1.LOCATION,(SELECT LOCATION FROM STUDENT WHERE
STUDENTID='p12'),'sdo_num_res =6',1) = 'TRUE' AND
S1.STUDENTID <> 'p12'
ORDER BY Distance;
/*----------------------------QUERY E--------------------------*/
SELECT *
FROM (
SELECT B.BUILDINGID,COUNT(B.BUILDINGID) AS StudentCount
FROM STUDENT S,BUILDING B
WHERE SDO_NN(B.SHAPE,S.LOCATION,'sdo_num_res=1') = 'TRUE'
GROUP BY B.BUILDINGID
ORDER BY StudentCount DESC
)
WHERE ROWNUM<=2;
/*----------------------------QUERY F--------------------------*/
SELECT S.STUDENTID AS STUDENT,B.BUILDINGID AS INSIDE_BUILDING
FROM TABLE(SDO_JOIN('STUDENT', 'LOCATION','BUILDING','SHAPE',
'mask=INSIDE')) C,STUDENT S,BUILDING B
WHERE SDO_INSIDE(S.LOCATION,B.SHAPE) = 'TRUE';