forked from galena100/Transform2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extract_data_from_database.sql
89 lines (72 loc) · 2.63 KB
/
Extract_data_from_database.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
88
89
/*
--------------------------------------------------
--1. used to export to csv for dataset - single hole
--------------------------------------------------
--litho
select HOLEID,GEOLFROM, GEOLTO, [VALUE] from
(
select HOLEID,GEOLFROM, GEOLTO, [VALUE]
,min(PRIORITY) over(partition by HOLEID,GEOLFROM,GEOLTO) min_prty
,PRIORITY
from GEODETAILS
where HOLEID ='GL1010' and NAME = 'CLLI_Litho_Type'
) a
where PRIORITY = min_prty
order by HOLEID, GEOLFROM,PRIORITY
--geophys
select -1* DEPTH DEPTH,[VALUE]
from QV_GEOPHYSDETAILS
where HOLEID = 'GL1010' and NAME = 'GRDE_gapi'
--where HOLEID in ('GL1010','GL1012','GL1015') and NAME IN ('GRDE_gapi','DENB_g_cc','MC2F_us_f','CADE_mm')
--dictionary
select LOOKUP, [DESCRIPTION] from QV_VS_LOOKUP_RW
where FIELDNAME = 'CLLI_Litho_Type' and LOOKUP in (select distinct VALUE from GEODETAILS where HOLEID = 'GL1010' and NAME = 'CLLI_Litho_Type')
--------------------------------------------------
--used to export to csv for dataset - three holes
--------------------------------------------------
--litho2
select case
when HOLEID = 'GL1010' THEN 'test001'
when HOLEID = 'GL1012' THEN 'test002'
else 'test003'
end as HOLEID
,GEOLFROM
, GEOLTO
, [VALUE]
from
(
select HOLEID,GEOLFROM, GEOLTO, [VALUE]
,min(PRIORITY) over(partition by HOLEID,GEOLFROM,GEOLTO) min_prty
,PRIORITY
from GEODETAILS
where HOLEID in ('GL1010','GL1012','GL1015') and NAME = 'CLLI_Litho_Type'
) a
where PRIORITY = min_prty
order by HOLEID, GEOLFROM,PRIORITY
--geophys2
select * from
(
select case
when HOLEID = 'GL1010' THEN 'test001'
when HOLEID = 'GL1012' THEN 'test002'
else 'test003'
end as HOLEID
, -1 * DEPTH DEPTH,NAME, [VALUE]
from QV_GEOPHYSDETAILS
--where HOLEID = 'GL1010' and NAME = 'GRDE_gapi'
where HOLEID in ('GL1010','GL1012','GL1015') and NAME IN ('GRDE_gapi','DENB_g_cc','MC2F_us_f','CADE_mm')
) c
pivot(
min(VALUE) for NAME in (GRDE_gapi,DENB_g_cc,MC2F_us_f,CADE_mm)
) as piv
order by HOLEID, DEPTH desc
--dictionary2
select LOOKUP, [DESCRIPTION] from QV_VS_LOOKUP_RW
where FIELDNAME = 'CLLI_Litho_Type' and LOOKUP in (select distinct VALUE from GEODETAILS where HOLEID in ('GL1010','GL1012','GL1015') and NAME = 'CLLI_Litho_Type')
-------------------------------------------------------------------------------
--3. used to export to single gamma as filtered csv for dataset - single hole
-------------------------------------------------------------------------------
select -1* DEPTH DEPTH,[VALUE]
from QV_GEOPHYSDETAILS
where HOLEID = 'GL1010' and NAME = 'GRDE_gapi' and DEPTH % 0.05 = 0 --the modulus filters out 4/5 of the data.
*/