Die Frage ist:SQL: 4 Bedingungen kombiniert mit OR
Bestimmen Namen aller Schiffe in Tabelle Schiffe, die eine Kombination von mindestens vier Kriterien aus der folgenden Liste erfüllen: numGuns = 8 Bohrung = 15 Verschiebung = 32000 type = bb lanced = 1915 Klasse = Kongo country = USA.
Ich fand die Antwort für diese Übung.
Die Antwort ist,
SELECT s.name from ship s,classes c
WHERE s.class=c.class AND
((numGuns = 8 AND bore = 15 AND displacement = 32000 AND type = 'bb')
OR (numGuns = 8 AND bore = 15 AND displacement = 32000 AND launched = 1915)
OR (numGuns = 8 AND bore = 15 AND displacement = 32000 AND c.class = 'Kongo')
OR (numGuns = 8 AND bore = 15 AND displacement = 32000 AND country = 'USA')
OR (numGuns = 8 AND bore = 15 AND type = 'bb' AND launched = 1915)
OR (numGuns = 8 AND bore = 15 AND type = 'bb' AND c.class = 'kongo')
OR (numGuns = 8 AND bore = 15 AND type = 'bb' AND country = 'USA')
OR (numGuns = 8 AND bore = 15 AND launched = 1915 AND c.class = 'Kongo')
OR (numGuns = 8 AND bore = 15 AND launched = 1915 AND country = 'USA')
OR (numGuns = 8 AND bore = 15 AND c.class = 'Kongo' AND country = 'USA')
OR (numGuns = 8 AND displacement = 32000 AND type = 'bb' AND launched = 1915)
OR (numGuns = 8 AND displacement = 32000 AND type = 'bb' AND c.class = 'kongo')
OR (numGuns = 8 AND displacement = 32000 AND type = 'bb' AND country = 'USA')
OR (numGuns = 8 AND displacement = 32000 AND launched = 1915 AND c.class = 'Kongo')
OR (numGuns = 8 AND displacement = 32000 AND launched = 1915 AND country = 'USA') O
Meine Frage ist,
Gibt es eine andere einfache Möglichkeit, die Bedingungen überprüfen. zum Beispiel
Bitte geben aussagekräftige Titel. –
Ja, verschieben Sie einfach Ihre 'WHERE'-Klauseln, um sie zu vereinfachen. – Ruslan
@Ruslan Was bedeutet? –