Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Select into returns a different class and not a different object

...

  • Find all 

    Code Block
    languagesql
    themeConfluence
    findAllCustomer()
    {
    	select * from Customer
    }
    

    Alternativ erlaubte Schreibweise:

    Code Block
    languagesql
    themeConfluence
    findAllCustomer()
    {
    	from Customer
    }


  • Where Condition

    Code Block
    languagesql
    themeConfluence
    findAllCustomerWhere()
    {
    	select * from Customer where city = "London"
    }


  • Where Condition mit Parameter

    Code Block
    languagesql
    themeConfluence
    findAllCustomerWhere(String city)
    {
    	select * from Customer where city = :city
    }

    Als Parameter können auch Objekte übergeben werden:

    Code Block
    languagesql
    themeConfluence
    findAllCustomerWhere(Customer customer)
    {
    	select * from Customer where customer = :customer
    }


  • Like Operator

    Code Block
    languagesql
    themeConfluence
    findAllCustomerLike()
    {
    	select * from Customer where city like "%L"
    }


  • Concat Funktion

    Code Block
    languagesql
    themeConfluence
    findAllCustomerLike(String city)
    {
    	select * from Customer where city like concat("%", :city)
    }


  • Rückgabe bestimmter Spalten

    Code Block
    languagesql
    themeConfluence
    findAllCustomerColumn()
    {
    	select customerid, city, address from Customer
    }


  • Speichert das Abfrageergebnis in einem benutzerdefiniertem Objekt eine andere Klasse

    Code Block
    languagesql
    themeConfluence
    findAllCustomer()
    {
    	select * customerid, city, address from Customer
        into myCustomObjectFlatCustomer
    }


  • Alias

    Code Block
    languagesql
    themeConfluence
    findAllCustomerAs()
    {
    	select * from Customer as c
        where c.city = "London"
    }


  • Logisch AND

    Code Block
    languagesql
    themeConfluence
    findAllCustomerAnd()
    {
    	select * from Customer where city = "London" and country = "UK"
    }


  • Logisch OR

    Code Block
    languagesql
    themeConfluence
    findAllCustomerOr()
    {
    	select * from Customer where city = "London" or city = "Berlin"
    }


  • MAX Funktion - Gibt den höchsten Unitprice zurück

    Code Block
    languagesql
    themeConfluence
    getOrderDetailMaxPrice()
    {
    	select max(unitprice) from Orderdetail result single
    }
    
    


  • MIN Funktion - Gibt den niedrigsten Unitprice zurück

    Code Block
    languagesql
    themeConfluence
    getOrderDetailMinPrice()
    {
    	select min(unitprice) from Orderdetail result single
    }


  • AVG Funktion - Gruppiert nach dem Produktnamen und berechnet den durchschnittlichen Bestellwert der Orderdetails

    Code Block
    languagesql
    themeConfluence
    getOrderDetailAvgPrice()
    {
    	select avg(unitprice) from Orderdetail
    	group by product.productname
    }


    Code Block
    languagesql
    themeConfluence
    getOrderDetailAvgPrice()
    {
    	select avg(unitprice) as price, product.productname from Orderdetail
    	group by product.productname
    }


  • ORDER BY Funktion 

    • Absteigende Sortierung

      Code Block
      languagesql
      themeConfluence
      getAllCustomerWithOrderByDesc()
      {
      	select * from Customer order by city desc
      }


    • Aufsteigende Sortierung

      Code Block
      languagesql
      themeConfluence
      getAllCustomerWithOrderByAsc()
      {
      	select * from Customer order by city asc
      }


  • Count Funktion

    Code Block
    languagesql
    themeConfluence
    getCountFromCustomerByCountry()
    {
    	select count(customerid) from Customer group by country
    }


  • Subselects

    Code Block
    languagesql
    themeConfluence
    getOrderDetailsFromLondon()
    {
    	select * from Orderdetail as detail
    	where detail.`order`.orderid in (select orderid from Order where customer.city = "London")
    }

    Alternative zu Subselects:

    Code Block
    languagesql
    themeConfluence
    getOrderDetailsFromLondon()
    {
    	select * from Orderdetail
    	where `order`.customer.city = "London"
    }


  • Komplexe Queries
    • Gibt alle Bestellungen aus London zurück und Gruppiert diese um die Summe aller Bestellungen aus London

      Code Block
      languagesql
      themeConfluence
      getOrderDetailsSumFromLondon()
      {
      	select sum(detail.unitprice) from Orderdetail as detail
      	where detail.`order`.orderid in (select orderid from Order where customer.city = "London")
      	group by detail.`order`.customer.city
      	result single
      }


    • Mögliche Kurzform

      Code Block
      languagesql
      themeConfluence
      getOrderDetailsSumFromLondon()
      {
      	select sum(unitprice) from Orderdetail
      	where `order`.customer.city = "London"
      	group by `order`.customer.city
      	result single
      }


...