Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7490569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:40:42+00:00 2026-05-29T15:40:42+00:00

I have no experience with relational databases and before I write C++ code to

  • 0

I have no experience with relational databases and before I write C++ code to implement solution to my problem, I would like to check if using a database would provide an easy solution. Here is my problem:

I have a set of physical samples and simple measurement, which produces a real number result on each sample. Measurement is performed multiple times on all samples available (new samples are added periodically) and results are stored in the database as table with SAMPLE_ID and RESULT columns. Each measurement is stored as a new table containing its results (table name identifies specific measurement). Or, if it makes more sense, each measurement adds a column to global table with current results (column name identifies specific measurement). I will create tables through C++ API and receive reports (query results) the same way. I need at least two reports (simple ASCII text is fine):

  1. List of all samples with their best (highest) result.
  2. For a small subset of measurements, list of samples where the result of most recent measurement is worse (lower) than any preceding one (in selected subset).

What is the database query to produce each report?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:40:43+00:00Added an answer on May 29, 2026 at 3:40 pm

    Yes, a database will work well for that.

    You will need a column to store either a date or a timestamp so you can distinguish between sample results. Without a column like that, “most recent measurement” is meaningless. (The order of rows in a table is essentially meaningless.)

    You probably don’t need anyone to develop a front end; try just entering data manually or loading a CSV file through the dbms’s bulk loader. (Every modern dbms has one; their names vary.)

    And you probably don’t need a reporting specialist to build reports. The query output is often all you need in research.

    Some queries are simple, and others are perhaps not simple but at least straightforward. Code below was tested in PostgreSQL, but should work in any dbms that supports common table expressions and row constructors.

    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);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have experience with relational databases where atomicity and normalization are fundamental principles. Do
I don't have lots of experience with relational databases and I'm struggling with this
Object-relational mapping has been well discussed, including on here. I have experience with a
Anyone have experience with algorithmic trading (like stocks)? Any good services to use to
Anyone have experience with adding a ReSharper profile to the VS2008 solution and share
I have experience with OCaml. You had to write a stub for every function
Does anyone have experience using the URL Rewrite Module (see here )? Can it
Does anyone have experience using makefiles for Visual Studio C++ builds (under VS 2005)
After using relational databases as back-end storage all my Windows programming life (currently .NET),
I've been reading a lot about Relational Databases using many JOIN statements on every

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.