예, 데이터베이스가 제대로 작동합니다.
샘플 결과를 구별 할 수 있도록 날짜 또는 시간 소인을 저장하는 열이 필요합니다. 그런 칼럼이 없다면, "가장 최근의 측정"은 의미가 없습니다. 테이블의 행 순서는 본질적으로 의미가 없습니다.
프런트 엔드를 개발할 필요가 없을 것입니다. 수동으로 데이터를 입력하거나 dbms의 대량 로더를 통해 CSV 파일을로드하십시오. (모든 최신 dbms에는 하나의 이름이 있으며 이름은 다릅니다.)
아마도 보고서 작성 전문가는 필요하지 않습니다. 쿼리 출력은 종종 연구에 필요한 모든 것입니다.
일부 검색어는 간단하고 다른 검색어는 단순하지는 않지만 간단합니다. 아래 코드는 PostgreSQL에서 테스트되었지만 공통 테이블 표현식과 행 생성자를 지원하는 dbms에서 작동해야합니다.
create table measurements (
sample_id integer not null,
measurement_time timestamp not null,
measurement real not null check(measurement >= 0 and measurement <= 30),
primary key (sample_id, measurement_time)
);
insert into measurements values
(1, '2012-02-02 08:03', 13.89),
(2, '2012-02-02 00:00', 13.86),
(1, '2012-02-02 00:25', 25.07),
(1, '2012-02-02 03:32', 25.38),
(1, '2012-02-02 05:47', 16.64),
(2, '2012-02-02 08:03', 16.16),
(2, '2012-02-02 07:25', 25.85),
(3, '2012-02-02 08:03', 14.78),
(3, '2012-02-02 09:29', 17.08),
(3, '2012-02-02 10:31', 13.41),
(4, '2012-02-02 12:38', 20.98),
(5, '2012-02-02 08:03', 25.00),
(5, '2012-02-02 14:02', 16.27),
(5, '2012-02-02 03:32', 12.10),
(5, '2012-02-02 17:47', 21.34),
(6, '2012-02-02 18:32', 17.16),
(6, '2012-02-02 18:33', 21.59),
(7, '2012-02-02 20:07', 21.47),
(8, '2012-02-02 21:58', 11.50),
(8, '2012-02-02 22:53', 21.01);
-- All samples with their highest measurement.
select sample_id, max(measurement)
from measurements
group by sample_id
order by sample_id;
-- Most recent measurement lower than any preceeding measurement.
-- Another way of saying this is that the max() measurement isn't the
-- latest measurement.
with max_measurements as (
select m.*
from measurements m
inner join (select sample_id, max(measurement) measurement
from measurements
group by sample_id) max_m
on max_m.sample_id = m.sample_id
and max_m.measurement = m.measurement
),
latest_measurement as (
select m.*
from measurements m
inner join (select sample_id, max(measurement_time) measurement_time
from measurements
group by sample_id) max_m
on max_m.sample_id = m.sample_id
and max_m.measurement_time = m.measurement_time
)
select m.*
from max_measurements m
where row(m.sample_id, m.measurement_time) not in (select sample_id, measurement_time
from latest_measurement);
정확히 묻는 중입니다. –
네가 맞다. 데이터베이스가 해결책 인 것 같다. 이제 데이터베이스를 디자인하는 분석가가 필요합니다. 사용자 프론트 엔드 인터페이스를 만드는 코드 개발자. 보고서 작성 전문가. 나는 당신이 무언가를 시험하고 질문을 나눌 수 있다고 생각합니다. 나는 투표를 닫습니다. – danihp
Sample_id가 고유하지 않은 것 같습니다. 데이터 + 측정 시간이 포함 된 세 번째 열이 필요하며 두 번째 테이블도 필요합니다. – wildplasser