-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueryI.sql
72 lines (72 loc) · 1.95 KB
/
QueryI.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
SELECT DISTINCT
dbe.case_number
FROM
dscr_events de
INNER JOIN
dscr_bail_events AS dbe
ON dbe.case_number = de.case_number
INNER JOIN
(
SELECT
cases.case_number
FROM
cases
WHERE
court IN
(
SELECT DISTINCT
court
FROM
cases
WHERE
query_court = 'BALTIMORE CITY'
)
)
AS ci
ON ci.case_number = de.case_number
WHERE
de.event_name = 'BSET'
AND dbe.event_name = 'INIT'
AND de.comment ilike '%cash%'
AND dbe.DATE >= '2018-1-1'
AND dbe.DATE < '2018-1-31'
AND de.DATE <= dbe.DATE
AND dbe.case_number NOT IN
(
SELECT DISTINCT
de.case_number
FROM
dscr_events de
INNER JOIN
dscr_bail_events AS dbe
ON dbe.case_number = de.case_number
INNER JOIN
(
SELECT
cases.case_number
FROM
cases
WHERE
court IN
(
SELECT DISTINCT
court
FROM
cases
WHERE
query_court = 'BALTIMORE CITY'
)
)
AS ci
ON ci.case_number = de.case_number
WHERE
dbe.event_name = 'INIT'
AND
(
de.event_name = 'BSET'
AND de.comment ilike '%hwob%'
)
AND dbe.DATE >= '2018-1-1'
AND dbe.DATE < '2018-1-31'
AND de.DATE <= dbe.DATE
)