Files
Yggdrasil/infotro/SDi/labs/database/README.md
T
2024-02-27 14:26:22 +01:00

9.6 KiB

Lab databases


Create & populate tables

relations.png

Queries

1) the description of all Function

SELECT `description` FROM `Function`

[!NOTE|label:Result]

"description"
"Fast backwards"
"Raise up the low frequencies. Cut off frequency : 200 Hz"
"Reduce the low frequencies. Cut off frequency : 200 Hz"
"Fast forwards"
"Tunes down"
"Tunes up"
"Plays to the next track"
"Open or close the player's tray"
"Pauses the current track"
"Plays the selected track"
"Select the preset 1"
"Select the preset 2"
"Select the preset 3"
"Plays to the previous track"
"Stores the current frequency to a preset"
"Stops the current track"
"Reduce the high frequencies.Cut off frequency : 4000 Hz"
"Raise up the high frequencies. Cut off frequency : 4000 Hz"
"Slow down fine tuning"
"Slow up fine tuning"
"Raise up the volume"
"Reduce the volume"
"Select the source of the input (BD, DVD, HDMI, ...)"
"Select the Audio format to use with the current source (2ch stereo, 5.1, 7.2, 9.2, ...)"

2) the name of manufacturers that have at least one entry in the Model table

SELECT `Manufacturer`.`manufacturerName`
FROM `Manufacturer`
WHERE EXISTS( SELECT *
             FROM `Model`
             WHERE `Model`.`manufacturerID`=`Manufacturer`.`manufacturerID`)

[!NOTE|label:Result]

"manufacturerName"
"HEVs"
"Sony"
"Onkyo"

3) the modelName of device models together with the manufacturerName of their manufacturers

SELECT `Model`.`modelName`, `Manufacturer`.`manufacturerName`
FROM `Model`, `Manufacturer`
WHERE `Model`.`manufacturerID` = `Manufacturer`.`manufacturerID`

[!NOTE|label:Result]

"modelName","manufacturerName"
"MHC-900","Sony"
"SDi-Ampli-01","HEVs" "SDi-CdDvd-01","HEVs"
"SDi-Tuner-01","HEVs"
"UBP-X800M2","Sony"
"TX-RZ70","Onkyo"

4) the description of the Function with functionLabel “Stop”

SELECT `Function`.`description`
FROM `Function`
WHERE `Function`.`functionLabel` like 'Stop'

[!NOTE|label:Result] "description"
"Stops the current track"

5) the functionLabel for Function with functionID > 10 and with a description containing the word “preset” (SQL wildcard character is “%”)

SELECT `Function`.`functionLabel`
FROM `Function`
WHERE `Function`.`functionID` > '10' AND `Function`.`description` like '%preset%'

[!NOTE|label:Result] "functionLabel"
"Preset 1"
"Preset 2"
"Preset 3"
"Save preset"

6) the product of the tables Code and FunctionList (with and without the JOIN keyword), as well as the number of entries in the resulting product table

With JOIN keyword
26 elements in 0,0003 seconds

SELECT `Code`.`codeValue`, `FunctionList`.`modelID`, `FunctionList`.`functionID`
FROM `Code`
JOIN `FunctionList`
ON `Code`.`codeID` = `FunctionList`.`codeID`;

[!NOTE|label:Result] "codeValue","modelID","functionID"
"7","1","1"
"124","1","10"
"125","1","16"
"547","1","9"
"698","1","4"
"59409854","3","8"
"78546723","3","7"
"81298355","3","16"
"84578346","3","9"
"84793478","3","10"
"95847623","3","14"
"458945040","2","17"
"458945041","2","18"
"458945042","2","2"
"458945043","2","3"
"458945044","2","21"
"458945045","2","22"
"1164736495","4","19"
"1164736496","4","20"
"1184894580","4","11"
"1184894581","4","12"
"1184894582","4","13"
"1184894589","4","15"
"1948573644","4","5"
"1948573645","4","6"
"1948573646","1","8"

Without JOIN keyword
26 elements in 0,0002 seconds

SELECT `Code`.`codeValue`, `FunctionList`.`modelID`, `FunctionList`.`functionID`
FROM `Code`, `FunctionList`
WHERE `Code`.`codeID` = `FunctionList`.`codeID`;

[!NOTE|label:Result] "codeValue","modelID","functionID"
"7","1","1"
"124","1","10"
"125","1","16"
"547","1","9"
"698","1","4"
"59409854","3","8"
"78546723","3","7"
"81298355","3","16"
"84578346","3","9"
"84793478","3","10"
"95847623","3","14"
"458945040","2","17"
"458945041","2","18"
"458945042","2","2"
"458945043","2","3"
"458945044","2","21"
"458945045","2","22"
"1164736495","4","19"
"1164736496","4","20"
"1184894580","4","11"
"1184894581","4","12"
"1184894582","4","13"
"1184894589","4","15"
"1948573644","4","5"
"1948573645","4","6"
"1948573646","1","8"

7) All codeValue for modelID 4

SELECT `Code`.`codeValue`
FROM `Code`
CROSS JOIN `FunctionList`
ON `Code`.`codeID` = `FunctionList`.`codeID`
WHERE `FunctionList`.`modelID` = 4;

[!NOTE|label:Result] "codeValue"
"1948573644"
"1948573645"
"1184894580"
"1184894581"
"1184894582"
"1184894589"
"1164736495"
"1164736496"

8) The number of codeValue for modelID 4

SELECT COUNT(`Code`.`codeValue`)
FROM `Code`
JOIN `FunctionList`
ON `Code`.`codeID` = `FunctionList`.`codeID`
WHERE `FunctionList`.`modelID` = 4;

[!NOTE|label:Result] 8

9) All codeValue and functionLabel for Model with modelName “SDi-Tuner-01”

SELECT `Code`.`codeValue`, `Function`.`functionLabel`
FROM `Model`
JOIN `FunctionList` ON `Model`.`modelID` = `FunctionList`.`modelID`
JOIN `Code` ON `FunctionList`.`codeID` = `Code`.`codeID`
JOIN `Function` ON `FunctionList`.`functionID` = `Function`.`functionID`
WHERE `Model`.`modelName` like 'SDi-Tuner-01'

[!NOTE|label:Result] "codeValue","functionLabel"
"1948573644","Frequency down"
"1948573645","Frequency up"
"1184894580","Preset 1"
"1184894581","Preset 2"
"1184894582","Preset 3"
"1184894589","Save preset"
"1164736495","Tune down"
"1164736496","Tune up"

10) The number of Function items per modelName

SELECT `Model`.`modelName`, COUNT(`FunctionList`.`functionID`)
FROM `Model`
LEFT JOIN `FunctionList` ON `Model`.`modelID` = `FunctionList`.`modelID`
GROUP BY `Model`.`modelName`

[!NOTE|label:Result] "modelName","COUNT(FunctionList.functionID)"
"MHC-900","6"
"SDi-Ampli-01","6"
"SDi-CdDvd-01","6"
"SDi-Tuner-01","8"
"UBP-X800M2","0"
"TX-RZ70","0"

11) All functionLabel and description with their corresponding modelID, functionID and codeID. Be sure to include all functionLabel even if they are not used in any device !

SELECT `Function`.`functionLabel`, `Function`.`description`, `FunctionList`.`modelID`, `FunctionList`.`codeID`
FROM `FunctionList`
RIGHT JOIN `Function` ON `FunctionList`.`functionID` = `Function`.`functionID`;

[!NOTE|label:Result] "functionLabel","description","modelID","codeID"
"Back","Fast backwards","1","1"
"Bass down","Raise up the low frequencies. Cut off frequency : 200 Hz","2","14"
"Bass up","Reduce the low frequencies. Cut off frequency : 200 Hz","2","15"
"Forward","Fast forwards","1","5"
"Frequency down","Tunes down","4","24"
"Frequency up","Tunes up","4","25"
"Next","Plays to the next track","3","7"
"Open/Close tray","Open or close the player's tray","1","26"
"Open/Close tray","Open or close the player's tray","3","6"
"Pause","Pauses the current track","1","4"
"Pause","Pauses the current track","3","9"
"Play","Plays the selected track","1","2"
"Play","Plays the selected track","3","10"
Preset 1","Select the preset 1","4","20"
"Preset 2","Select the preset 2","4","21"
"Preset 3","Select the preset 3","4","22"
"Previous","Plays to the previous track","3","11"
"Save preset","Stores the current frequency to a preset","4","23"
"Stop","Stops the current track","1","3"
"Stop","Stops the current track","3","8"
"Treble down","Reduce the high frequencies.Cut off frequency : 4000 Hz","2","12"
"Treble up","Raise up the high frequencies. Cut off frequency : 4000 Hz","2","13"
"Tune down","Slow down fine tuning","4","18""Tune up","Slow up fine tuning","4","19"
"Volume down","Raise up the volume","2","16"
"Volume up","Reduce the volume","2","17"
"Input source","Select the source of the input (BD, DVD, HDMI, ...)",NULL,NULL
"Audio format","Select the Audio format to use with the current source (2ch stereo, 5.1, 7.2, 9.2, ...)",NULL,NULL

12) All functionLabel and description of non-used functions in any device. (insert beforehand a new function in Function, with no reference in the FunctionList table). Add an unused function in the CSV file

SELECT `Function`.`functionLabel`, `Function`.`description`
FROM `FunctionList`
RIGHT JOIN `Function` ON `FunctionList`.`functionID` = `Function`.`functionID`
WHERE `FunctionList`.`modelID` is NULL

[!NOTE|label:Result] "functionLabel","description"
"Input source","Select the source of the input (BD, DVD, HDMI, ...)"
"Audio format","Select the Audio format to use with the current source (2ch stereo, 5.1, 7.2, 9.2, ...)"
"Test Function","This function should not be referenced in the FunctionList"

13) Add a VIEW to your DB to list all HEVs appliances with their manufacturerName, modelName, typeLabel, functionLabel and codeValue


[!NOTE|label:Result]

Test constraints