2014-11-17 15:39:27 +01:00
|
|
|
# Load Tables
|
|
|
|
CREATE TABLE IF NOT EXISTS students FROM TBL FILE 'test/students.tbl';
|
2014-12-03 16:32:56 +01:00
|
|
|
CREATE TABLE IF NOT EXISTS test_big FROM TBL FILE 'test/lin_xxs.tbl';
|
2014-11-17 15:39:27 +01:00
|
|
|
CREATE TABLE IF NOT EXISTS companies FROM TBL FILE 'test/tables/companies.tbl';
|
|
|
|
CREATE TABLE IF NOT EXISTS employees FROM TBL FILE 'test/tables/employees.tbl';
|
2015-01-06 19:20:52 +01:00
|
|
|
CREATE TABLE IF NOT EXISTS test (v1 INTEGER, v2 INTEGER, v3 INTEGER);
|
2014-11-17 22:13:29 +01:00
|
|
|
# SELECT
|
|
|
|
SELECT * FROM students WHERE grade <= 2.0;
|
|
|
|
# SUB-SELECT
|
2014-11-17 15:39:27 +01:00
|
|
|
SELECT name, city, grade FROM (SELECT * FROM students WHERE city = 'Potsdam') t1 WHERE grade <= 1.5 OR grade >= 3.5;
|
|
|
|
# GROUP
|
2015-01-05 16:22:57 +01:00
|
|
|
SELECT city, AVG(grade) AS average, MIN(grade) AS best, MAX(grade) AS worst FROM students GROUP BY city;
|
2014-11-17 15:39:27 +01:00
|
|
|
# UNION
|
|
|
|
SELECT * FROM students WHERE grade = 1.3 UNION SELECT * FROM students WHERE grade = 3.7;
|
2014-11-26 00:26:20 +01:00
|
|
|
# JOIN
|
2014-11-26 12:19:33 +01:00
|
|
|
SELECT * FROM companies JOIN employees ON company_id = employee_company_id;
|
|
|
|
# INSERT
|
2014-12-03 16:32:56 +01:00
|
|
|
INSERT INTO students VALUES ('Max Mustermann', 10101, 'Musterhausen', 1.7);
|
|
|
|
# CREATE
|
|
|
|
CREATE TABLE IF NOT EXISTS test (v1 INTEGER, v2 INTEGER, v3 INTEGER);
|
|
|
|
# INSERT/SELECT
|
2014-12-15 13:19:12 +01:00
|
|
|
INSERT INTO test VALUES (1, 23, 45);
|
2014-12-03 16:32:56 +01:00
|
|
|
INSERT INTO test VALUES (1, 23, 45);
|
|
|
|
INSERT INTO test VALUES (1, 23, 45);
|
|
|
|
SELECT * FROM test;
|
|
|
|
# CREATE/INSERT/SELECT
|
|
|
|
CREATE TABLE IF NOT EXISTS test (v1 INTEGER, v2 INTEGER, v3 INTEGER);
|
|
|
|
INSERT INTO test VALUES (1, 12, 43);
|
2014-12-05 09:37:59 +01:00
|
|
|
SELECT * FROM test;
|
2015-01-06 19:20:52 +01:00
|
|
|
# PREPARE 1
|
|
|
|
PREPARE select_test: SELECT * FROM students WHERE grade = ?;
|
|
|
|
# EXECUTE 1
|
|
|
|
EXECUTE select_test(2.0);
|
|
|
|
# PREPARE 2
|
2015-01-07 14:02:14 +01:00
|
|
|
PREPARE insert_test {
|
|
|
|
INSERT INTO test VALUES (?, 0, 0);
|
|
|
|
INSERT INTO test VALUES (?, 0, 0);
|
|
|
|
INSERT INTO test VALUES (?, 0, 0);
|
|
|
|
INSERT INTO test VALUES (?, 0, 0);
|
|
|
|
INSERT INTO test VALUES (?, 0, 0);
|
|
|
|
};
|
|
|
|
EXECUTE insert_test(1, 2, 3, 4 ,5);
|
2015-01-06 19:20:52 +01:00
|
|
|
SELECT * FROM test;
|
|
|
|
# EXECUTE 2
|
|
|
|
EXECUTE insert_test(1, 2, 3, 4, 5);
|
2014-12-05 09:37:59 +01:00
|
|
|
#! GROUP
|
|
|
|
SELECT AVG(grade) FROM (SELECT city, AVG(grade) FROM students GROUP BY city) t1
|
|
|
|
#! UNION (kills hyrise)
|
2014-12-15 13:19:12 +01:00
|
|
|
SELECT name FROM students WHERE grade > 2.0 UNION SELECT name FROM students
|