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):
- List of all samples with their best (highest) result.
- 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?
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.