Übung Vorlage 1

--Tabelle customer aus chinook abfragen
SELECT * FROM uchinook.customer;

-- Schema wechseln
ALTER SESSION SET current_schema=uchinook;

-- Alle Spalten abfragen

SELECT * FROM customer;

-- In welchen Ländern wohnen unsere Kunden?

SELECT Country FROM customer;

--DISTINCT 

SELECT DISTINCT Country from customer;

-- alphabetisch sortiert  Sortieren aufsteigend (ASC) oder absteigend (DESC)
SELECT DISTINCT Country from customer ORDER BY Country ASC;

SELECT DISTINCT Country from customer ORDER BY Country DESC;

-- 'HALLO WELT!'

SELECT 'HALLO WELT!' from customer;

-- Vorname und Nachname in einer Spalte (Kunde)

SELECT firstname || ' ' || lastname from customer;

SELECT firstname || ' ' || lastname AS Name from customer;

-- Leonie Köhler aus Deutschland wohnt im schönen Städtchen Stuttgart

SELECT firstname || ' ' || lastname || ' aus ' || country || ' wohnt im schönen Städtchen ' || city AS Antwortsatz from customer;

-- Nur Leonie

SELECT firstname || ' ' || lastname || ' aus ' || country || ' wohnt im schönen Städtchen ' || city AS Antwortsatz from customer WHERE firstname='Leonie';

-- Alle Kunden aus Brasilien

SELECT firstname, lastname, country from customer WHERE country='Brazil';

--upper lower

-- zeigt nur extra Spalte an wo alles klein ist
SELECT firstname, lastname, country, LOWER(country) from customer WHERE country='Brazil';

-- hier wird ebenfalls nach kleine geschriebenen Sachen gesucht
SELECT firstname, lastname, country  from customer WHERE LOWER(country)='brazil';

-- ALLE Kunden aus Ländern mit B

SELECT firstname, lastname, country from customer WHERE country LIKE 'B%';

-- Länder mit land am Ende

SELECT firstname, lastname, country from customer WHERE country LIKE '%land';
  
-- Länder mit land - egal an welcher Stelle

SELECT firstname, lastname, country from customer WHERE country LIKE '%land%';

-- Kunden aus Schweden und aus Dänemark

SELECT firstname, lastname, country from customer WHERE country='Sweden' AND country='Denmark';

--OR

SELECT firstname, lastname, country from customer WHERE country='Sweden' OR country='Denmark';

--Kunden ohne company IS 

SELECT firstname, lastname, country, company from customer WHERE company IS NULL;

-- Firmenkunden

SELECT firstname, lastname, country, company from customer WHERE company IS NOT NULL;

-- Rechnungen über 10€

SELECT InvoiceId, CustomerId, Total from Invoice WHERE total > 10;

-- Rechnungen vor dem 1. Februar 2009

SELECT InvoiceId, CustomerId, Total, InvoiceDate from Invoice WHERE InvoiceDate < '01.02.2009' ORDER BY InvoiceDate ASC;

-- Rechnungen nach dem 1. Dezember 2013

SELECT InvoiceId, CustomerId, Total, InvoiceDate from Invoice WHERE InvoiceDate > '01.12.2013';

-- Rechnungen aus dem Februar 2012

SELECT InvoiceId, CustomerId, Total, InvoiceDate from Invoice WHERE InvoiceDate >= '01.02.2012' AND InvoiceDate < '01.03.2012' ;

-- Alle Rechnungspositionen, bei denen die Menge größer als 1 ist

-- gibt keine mit mehr als 1??
SELECT InvoiceLineId, Quantity from InvoiceLine WHERE Quantity > 1;

-- Positionspreis berechnen (Menge x Preis)

SELECT InvoiceLineId, Quantity, UnitPrice, Quantity*UnitPrice as Positionspreis from InvoiceLine ORDER BY Positionspreis DESC;
Last modified 2022.10.10