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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| CREATE DATABASE '..\Data\Base.fdb' page_size 4096 DEFAULT CHARACTER SET ISO8859_1;
-- =================================
-- Création de la table 'DATA_10MIN'
-- =================================
CREATE TABLE DATA_10MIN (
NOM_PROJET VARCHAR(10) NOT NULL collate fr_fr,
REF_TURBINE VARCHAR(10) NOT NULL collate fr_fr,
DATE_HEURE TIMESTAMP NOT NULL,
PUISS_ACTIVE_PRODUITE INTEGER NOT NULL,
VITESSE_VENT_NACELLE INTEGER NOT NULL
);
-- ===========================
-- Insertion dans 'DATA_10MIN'
-- ===========================
insert into data_10min (nom_projet,ref_turbine,date_heure,puiss_active_produite,vitesse_vent_nacelle) values ('x','T1','2016-05-05 08:01:00',186, 10);
insert into data_10min (nom_projet,ref_turbine,date_heure,puiss_active_produite,vitesse_vent_nacelle) values ('x','T1','2016-05-05 08:15:00',175, 15);
insert into data_10min (nom_projet,ref_turbine,date_heure,puiss_active_produite,vitesse_vent_nacelle) values ('x','T2','2016-05-05 08:01:00',255, 11);
insert into data_10min (nom_projet,ref_turbine,date_heure,puiss_active_produite,vitesse_vent_nacelle) values ('x','T2','2016-05-05 08:22:00',022, 14);
insert into data_10min (nom_projet,ref_turbine,date_heure,puiss_active_produite,vitesse_vent_nacelle) values ('x','T3','2016-05-05 08:01:00',075, 0);
insert into data_10min (nom_projet,ref_turbine,date_heure,puiss_active_produite,vitesse_vent_nacelle) values ('x','T3','2016-05-05 08:22:00',432, 17);
insert into data_10min (nom_projet,ref_turbine,date_heure,puiss_active_produite,vitesse_vent_nacelle) values ('x','T4','2016-05-05 08:22:00',128, 12);
insert into data_10min (nom_projet,ref_turbine,date_heure,puiss_active_produite,vitesse_vent_nacelle) values ('x','T4','2016-05-05 08:15:00',133, 23);
insert into data_10min (nom_projet,ref_turbine,date_heure,puiss_active_produite,vitesse_vent_nacelle) values ('x','T5','2016-05-05 08:01:00',105, 33);
insert into data_10min (nom_projet,ref_turbine,date_heure,puiss_active_produite,vitesse_vent_nacelle) values ('x','T5','2016-05-05 08:15:00',017, 18);
insert into data_10min (nom_projet,ref_turbine,date_heure,puiss_active_produite,vitesse_vent_nacelle) values ('x','T6','2016-05-05 08:22:00',177, 13);
insert into data_10min (nom_projet,ref_turbine,date_heure,puiss_active_produite,vitesse_vent_nacelle) values ('x','T6','2016-05-05 08:15:00',205, 27);
-- ======================
-- Vidage de 'data_10min'
-- ======================
select * from data_10min;
NOM_PROJET REF_TURBINE DATE_HEURE PUISS_ACTIVE_PRODUITE VITESSE_VENT_NACELLE
========== =========== ========================= ===================== ====================
x T1 2016-05-05 08:01:00.0000 186 10
x T1 2016-05-05 08:15:00.0000 175 15
x T2 2016-05-05 08:01:00.0000 255 11
x T2 2016-05-05 08:22:00.0000 22 14
x T3 2016-05-05 08:01:00.0000 75 0
x T3 2016-05-05 08:22:00.0000 432 17
x T4 2016-05-05 08:22:00.0000 128 12
x T4 2016-05-05 08:15:00.0000 133 23
x T5 2016-05-05 08:01:00.0000 105 33
x T5 2016-05-05 08:15:00.0000 17 18
x T6 2016-05-05 08:22:00.0000 177 13
x T6 2016-05-05 08:15:00.0000 205 27
-- ============
-- Requête N° 1
-- ============
select date_heure,
ref_turbine,
puiss_active_produite,
vitesse_vent_nacelle
from data_10min
where nom_projet = 'x'
and ref_turbine in ('T1','T2','T4','T5')
and date_heure between '2016-05-05 08:00:00' and '2016-05-05 10:00:00'
order by date_heure, ref_turbine
;
DATE_HEURE REF_TURBINE PUISS_ACTIVE_PRODUITE VITESSE_VENT_NACELLE
========================= =========== ===================== ====================
2016-05-05 08:01:00.0000 T1 186 10
2016-05-05 08:01:00.0000 T2 255 11
2016-05-05 08:01:00.0000 T5 105 33
2016-05-05 08:15:00.0000 T1 175 15
2016-05-05 08:15:00.0000 T4 133 23
2016-05-05 08:15:00.0000 T5 17 18
2016-05-05 08:22:00.0000 T2 22 14
2016-05-05 08:22:00.0000 T4 128 12
-- ============
-- Requête N° 2
-- ============
with cte as (
select date_heure,
max(case ref_turbine when 'T1' then puiss_active_produite else null end) as puiss_active_produite_t1,
max(case ref_turbine when 'T2' then puiss_active_produite else null end) as puiss_active_produite_t2,
max(case ref_turbine when 'T4' then puiss_active_produite else null end) as puiss_active_produite_t4,
max(case ref_turbine when 'T5' then puiss_active_produite else null end) as puiss_active_produite_t5,
max(case ref_turbine when 'T1' then vitesse_vent_nacelle else null end) as vitesse_vent_nacelle_t1,
max(case ref_turbine when 'T2' then vitesse_vent_nacelle else null end) as vitesse_vent_nacelle_t2,
max(case ref_turbine when 'T4' then vitesse_vent_nacelle else null end) as vitesse_vent_nacelle_t4,
max(case ref_turbine when 'T5' then vitesse_vent_nacelle else null end) as vitesse_vent_nacelle_t5
from data_10min
where nom_projet = 'x'
and ref_turbine in ('T1','T2','T4','T5')
and date_heure between '2016-05-05 08:00:00' and '2016-05-05 10:00:00'
group by date_heure
order by date_heure
)
select * from cte;
DATE_HEURE PUISS_ACTIVE_PRODUITE_T1 PUISS_ACTIVE_PRODUITE_T2 PUISS_ACTIVE_PRODUITE_T4 PUISS_ACTIVE_PRODUITE_T5 VITESSE_VENT_NACELLE_T1 VITESSE_VENT_NACELLE_T2 VITESSE_VENT_NACELLE_T4 VITESSE_VENT_NACELLE_T5
========================= ======================== ======================== ======================== ======================== ======================= ======================= ======================= =======================
2016-05-05 08:01:00.0000 186 255 <null> 105 10 11 <null> 33
2016-05-05 08:15:00.0000 175 <null> 133 17 15 <null> 23 18
2016-05-05 08:22:00.0000 <null> 22 128 <null> <null> 14 12 <null>
exit
Expected end of statement, encountered EOF
Appuyez sur une touche pour continuer... |
Partager