품질 Q 그림 관건 SQL 연구 - 날짜 데이터 처리
-- :
-- , , , --
-- UI: DatePicker, Q ; , FullCalendar
-- Q PCR , Cell :
---- : 、
---- : 、
---- : 、 ; 、
-- , datepicker (yyyymm) sql, “ ”
select distinct replace(t.PUB_DATE, '-') from T_PCR t where replace(substr(t.PUB_DATE, 1, 7), '-') ='201711';
-- : , PCR
--
create table qsb_data_test01
(
occur_date varchar2(10),
prob_type varchar2(10),
prob_desc varchar2(100),--
grade varchar2(10)--
)
--
insert into qsb_data_test01 (OCCUR_DATE, PROB_TYPE, PROB_DESC, GRADE)
values ('20180101', ' ', ' ', '');
insert into qsb_data_test01 (OCCUR_DATE, PROB_TYPE, PROB_DESC, GRADE)
values ('20180102', ' ', ' ', '');
insert into qsb_data_test01 (OCCUR_DATE, PROB_TYPE, PROB_DESC, GRADE)
values ('20180103', ' ', ' ', '');
insert into qsb_data_test01 (OCCUR_DATE, PROB_TYPE, PROB_DESC, GRADE)
values ('20180104', ' ', ' ', '');
insert into qsb_data_test01 (OCCUR_DATE, PROB_TYPE, PROB_DESC, GRADE)
values ('20180104', ' ', ' ', '');
insert into qsb_data_test01 (OCCUR_DATE, PROB_TYPE, PROB_DESC, GRADE)
values ('20180106', ' ', ' ', '');
insert into qsb_data_test01 (OCCUR_DATE, PROB_TYPE, PROB_DESC, GRADE)
values ('20171231', ' ', ' ', '');
insert into qsb_data_test01 (OCCUR_DATE, PROB_TYPE, PROB_DESC, GRADE)
values ('20171230', ' ', ' ', '');
select * from qsb_data_test01 t;
-- : 1
select to_char(trunc(sysdate, 'mm'),'yyyymmdd') from dual;
-- :
select to_char(sysdate,'yyyymmdd') from dual;
-- ( )
-- DatePicker ? ; , ;
-- , 。
-- : , DatePicker 【 】
-- , , ; , ( )
select * from qsb_data_test01 t
where substr(t.occur_date, 1, 6) ='201801'
and t.occur_date<=to_char(sysdate,'yyyymmdd');
-- , ( -3, / -2)
select t.occur_date,
t.prob_type,
(case t.prob_type
when ' ' then
'3'
when ' ' then
'2'
when ' ' then
'2'
end) as
from qsb_data_test01 t;
-- ,
select t.occur_date as ,
max(case t.prob_type
when ' ' then
'3'
when ' ' then
'2'
when ' ' then
'2'
end) as
from qsb_data_test01 t
group by t.occur_date
order by t.occur_date;
-- , ;
select cc.occur_date,
(case cc.grade
when '3' then
'red'
when '2' then
'yello'
end) q_color
from (select t.occur_date,
max(case t.prob_type
when ' ' then
'3'
when ' ' then
'2'
when ' ' then
'2'
end) as grade
from qsb_data_test01 t
where substr(t.occur_date, 1, 6) = '201712'
and t.occur_date <= to_char(sysdate, 'yyyymmdd') --
group by t.occur_date
order by t.occur_date) cc
--
-- , ( SQL): , ,
-- , :
----1. , , : == , <=
----2.
----3. , 、 , ( )
----4. , , ( )
----5. FullCalendar, Events ,
--
-- :Oracle
SELECT TO_DATE('2017-01-01', 'yyyy-MM-dd') + ROWNUM - 1 as daylists
FROM DUAL
CONNECT BY ROWNUM <=
trunc( to_date('2017-12-31', 'yyyy-MM-dd') - --
to_date('2017-01-01', 'yyyy-MM-dd') --
) + 1;
-- : ( )X , X=60, 60
SELECT trunc(sysdate, 'dd') + ROWNUM - 60 as daylists
FROM DUAL
CONNECT BY ROWNUM <=
trunc(trunc(sysdate, 'dd') - (trunc(sysdate, 'dd') - 60));
-- , ,
select t1.daylists
from (SELECT to_char(trunc(sysdate, 'dd') + ROWNUM - 30, 'yyyymmdd') as daylists
FROM DUAL
CONNECT BY ROWNUM <=
trunc(trunc(sysdate, 'dd') - (trunc(sysdate, 'dd') - 30))) t1
where t1.daylists not in (select t.occur_date from qsb_data_test01 t)
order by t1.daylists;
-- : not exist not in
select t1.daylists
from (SELECT to_char(trunc(sysdate, 'dd') + ROWNUM - 30, 'yyyymmdd') as daylists
FROM DUAL
CONNECT BY ROWNUM <=
trunc(trunc(sysdate, 'dd') - (trunc(sysdate, 'dd') - 30))) t1
where not exists (select t.occur_date
from qsb_data_test01 t
where t.occur_date = t1.daylists)
order by t1.daylists;
--------------------------------END.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Redash에서 풀다운 필터 만들기 ~ BigQuery의 public-data를 사용하여 연습 ~Redash는 SQL이 쓸 수만 있으면, 나머지는 GUI로 플롯을 좋은 느낌으로 만들 수 있으므로 매우 편리합니다. 이 편리한 기능보다 편리하게 사용할 수 있게 되고 싶습니다. 나 자신 SQL 돌출이라고 하는 일도 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.