From 03acb1a5311480e69fb06fe42c59ed9db653cf41 Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 27 Oct 2023 17:08:20 +0200 Subject: [PATCH] added tasks 0 to 1 --- tasks/01-select-intro.sql | 29 +++++++++++++++++++++++++++++ tasks/02-create-table.sql | 24 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tasks/01-select-intro.sql create mode 100644 tasks/02-create-table.sql diff --git a/tasks/01-select-intro.sql b/tasks/01-select-intro.sql new file mode 100644 index 0000000..708ec31 --- /dev/null +++ b/tasks/01-select-intro.sql @@ -0,0 +1,29 @@ +-- Active: 1697184303960@@127.0.0.1@3306 + +# Date: 13.10.2023 +# Author: Sven Vogel + +# --------------------------------------------- +# setup database schema +CREATE SCHEMA IF NOT EXISTS task01; +USE task01; + +# select a single number +SELECT 5 AS number; +# interpret value as hex +SELECT hex(255) AS hexnum; + +# intger encode of ascii '5' +SELECT ASCII('5'); +SELECT BIN(65); +# binary value of 'A' +SELECT BIN(ASCII('A')); +# binary encode of 'Mucke' +SELECT CONCAT_WS( + ' ', + BIN(ASCII('M')), + BIN(ASCII('u')), + BIN(ASCII('c')), + BIN(ASCII('k')), + BIN(ASCII('e')) +); \ No newline at end of file diff --git a/tasks/02-create-table.sql b/tasks/02-create-table.sql new file mode 100644 index 0000000..c60f485 --- /dev/null +++ b/tasks/02-create-table.sql @@ -0,0 +1,24 @@ +-- Active: 1697184303960@@127.0.0.1@3306 +CREATE SCHEMA IF NOT EXISTS task02; +USE task02; + +DROP TABLE IF EXISTS fruits; + +CREATE TABLE fruits ( + id INT PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(45) NOT NULL, + color VARCHAR(10) +); + +INSERT INTO fruits (name, color) VALUES ('Banane', 'gelb'); +INSERT INTO fruits (name, color) VALUES ('Kiwi', 'grün'); +INSERT INTO fruits (name, color) VALUES ('Apfel', 'grün'); +INSERT INTO fruits (name, color) VALUES ('Apfel', 'rot'); +INSERT INTO fruits (name, color) VALUES ('Erdbeere', 'rot'); +INSERT INTO fruits (name, color) VALUES ('Himbeere', 'rot'); +INSERT INTO fruits (name, color) VALUES ('Birne', 'grun'); + +SELECT * FROM fruits; +SELECT name FROM fruits WHERE color = 'rot'; +SELECT name FROM fruits; +SELECT DISTINCT name FROM fruits; \ No newline at end of file