So, in my mind(which only I can read), I'll try to explain.tvrfan wrote: ↑2024 Dec 11, 15:58 PIVOT TABLES ?? My other half thinks they are a total waste of time, and reckons everything you can do in a pivot table can be done with more straightforward (and easier?) cell logic formulae like IF-THEN-ELSE and collection filters and sometimes adding a 'type' column to filter with. She has a strong background in finance, so I believe her (I have never done much in excel myself, so I'm just passing this on...).
I still think this should be another topic, maybe I'll start that soon, I have a couple weeks off work coming up.
Database Design:
We have known calibration constants, variables, functions and tables with known descriptions(strategy docs).
We have known hardware, strategies and calibrations.
This could be the start of base tables in database:
- CalibrationConstants, RAMVariables, FoxFunctions.
- HardwareCode, StrategyCode
So, my idea of a pivot table would be where a HardwareCode_Strategy(hardwarecode_id, strategycode_id);
Its basically a many to many pivot table.
Code: Select all
HardwareCode(id, code)
1, SD47
2, SD48
3, ML1441
CalibrationCode(id, code)
1, KID
2, HEN
3, JOG
4, LAW
CalibrationCode_Revision(id,calibration_id, revision)
1, 1, 0
2, 1, 1
3, 1, 2
4, 2, 0
5, 2, 1
6, 2, 2
StrategyCode(id, name)
1, CRAI8
2, LHBH1
3, CDAN2
4, GFUB
Code: Select all
CalibrationCode_StrategyCode(calibration_id, strategy_id)
2, 1
2, 3
2,4
HardwareCode_Strategy(hardware_id, strategy_id)
2, 2
Code: Select all
SELECT
hc.id AS hardware_id,
hc.code AS hardware_code,
sc.id AS strategy_id,
sc.name AS strategy_name,
cc.id AS calibration_id,
cc.code AS calibration_code,
ccr.revision AS calibration_revision
FROM
HardwareCode_Strategy hs
JOIN
HardwareCode hc ON hs.hardware_id = hc.id
JOIN
StrategyCode sc ON hs.strategy_id = sc.id
JOIN
CalibrationCode_StrategyCode ccs ON sc.id = ccs.strategy_id
JOIN
CalibrationCode cc ON ccs.calibration_id = cc.id
LEFT JOIN
CalibrationCode_Revision ccr ON cc.id = ccr.calibration_id
WHERE
hc.code = 'SD48' -- Filter for SD48 hardware
ORDER BY
hc.code, sc.name, cc.code, ccr.revision;
Code: Select all
hardware_id hardware_code strategy_id strategy_name calibration_id calibration_code calibration_revision
2 SD48 2 LHBH1 3 KID 0
2 SD48 2 LHBH1 3 KID 1
2 SD48 3 LHBH1 3 KID 2
The above is not necessarily good data, I just typed it out from my brain.
What I'm trying to explain is:
A pivot table is a specific database table used to implement a many-to-many relationship, containing foreign keys to both related tables.