\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{PenumbraGamer} \pdfinfo{ /Title (sql-tsaalen-3-lehrjahr.pdf) /Creator (Cheatography) /Author (PenumbraGamer) /Subject (SQL-TSAALEN 3.Lehrjahr Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{0BA352} \definecolor{LightBackground}{HTML}{EFF9F4} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{SQL-TSAALEN 3.Lehrjahr Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{PenumbraGamer} via \textcolor{DarkBackground}{\uline{cheatography.com/181291/cs/42986/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}PenumbraGamer \\ \uline{cheatography.com/penumbragamer} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 9th April, 2024.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{1.59264 cm} x{3.38436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Funktionen}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{AVG}}(Feldname) & Gibt den Mittelwert von Werten in einem bestimmten Feld aus \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{MAX}}(Feldname) & Gibt den gr{\"o}{\ss}ten Wert einer Menge aus Werten aus \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{MIN}}(Feldname) & Gibt den kleinsten Wert einer Menge aus \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} {\bf{SUM}}(Feldname) & Gibt die Summe einer Menge von Zahlen aus \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{Count}}(Feldname) & Gibt die Zahl der Datens{\"a}tze aus \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} {\bf{YEAR}}(Feldname) & Gibt die Jahreszahl eines Datums aus \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{CURDATE()}} & Gibt das aktuelle Datum aus \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{HAVING}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SELECT Auswahlliste \newline % Row Count 1 (+ 1) FROM Tabellenliste \newline % Row Count 2 (+ 1) GROUP BY Gruppenliste \newline % Row Count 3 (+ 1) {[}HAVING Suchbedingungen{]} \newline % Row Count 4 (+ 1) Die HAVING-Klausel erfüllt auf Gruppenebene die gleiche Aufgabe wie die WHERE-Klausel für die \newline % Row Count 6 (+ 2) gesamte Auswahlliste der SELECT-Anweisung und legt somit eine Suchbedingung für eine Gruppe \newline % Row Count 8 (+ 2) oder ein Aggregat fest. \newline % Row Count 9 (+ 1) Sprich, nachdem du mit deinen Anweisungen einen geordneten Table hast kannst du mit Having diesen nochmal durchsuchen oder filtern. \newline % Row Count 12 (+ 3) Hinweis: Die WHERE-Klausel wird vor der HAVING-Klausel bearbeitet. D.h. Datens{\"a}tze die der \newline % Row Count 14 (+ 2) WHERE-Bedingung nicht entsprechen werden erst gar nicht gruppiert. \newline % Row Count 16 (+ 2) In der HAVING-Klausel werden weitere Bedingungen auf Gruppenebene hinzugefügt.% Row Count 18 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.59264 cm} x{3.38436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{SELECTS}} \tn % Row 0 \SetRowColor{LightBackground} ORDER BY \textless{}Feldname\textgreater{} & Die ORDER BY-Klausel bestimmt die Kriterien der Zeilensortierung bei Abfrageergebnissen. Ohne Zusatzangabe wird standardm{\"a}{\ss}ig eine aufsteigende Reihenfolge (ASC/ 1234) angezeigt. M{\"o}chten Sie eine absteigende Reihenfolge (DESC/4 3 2 1) so k{\"o}nnen Sie dies durch die Angabe von "DESC" hinter dem entsprechenden Attribut erzielen \tn % Row Count 13 (+ 13) % Row 1 \SetRowColor{white} Beispiel & SELECT * FROM Mitarbeiter WHERE Entfernung \textgreater{} 15 ORDER BY Wohnort \tn % Row Count 16 (+ 3) % Row 2 \SetRowColor{LightBackground} Zusatz & Die ORDER BY-Klausel: \{\{nl\}\}• Wird nach der WHERE-Klausel geschrieben \{\{nl\}\}•kann Ausdrücke von Spaltenwerten enthalten \{\{nl\}\}• kann die Spalten-Folgenummer enthalten\{\{nl\}\} • kann ein mehrfach verschachteltes Kriterium enthalten \{\{nl\}\}• Priorit{\"a}t gilt von links nach rechts\{\{nl\}\} Beispiele:\{\{nl\}\} ORDER BY Job, Vorname DESC \tn % Row Count 29 (+ 13) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Union / Intersect}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Vereinigung (UNION) \newline % Row Count 1 (+ 1) Wegen einer Werbeaktion sollen sowohl Kunden als auch \newline % Row Count 3 (+ 2) Lieferanten angeschrieben werden. Dies soll durch einen \newline % Row Count 5 (+ 2) einzigen Zugriff auf die Datenbank realisiert werden. \newline % Row Count 7 (+ 2) Somit ist es notwendig, die Relation "Kunde" mit der \newline % Row Count 9 (+ 2) Relation "Lieferant" zu vereinigen. \newline % Row Count 10 (+ 1) Dies ist m{\"o}glich durch das Schlüsselwort "UNION", mit \newline % Row Count 12 (+ 2) dem zwei oder mehr Tabellen oder Abfragen kombiniert \newline % Row Count 14 (+ 2) werden k{\"o}nnen. D.h. "UNION" gibt die Ergebnisse zweier \newline % Row Count 16 (+ 2) Abfragen abzüglich der doppelt vorkommenden Zeilen \newline % Row Count 18 (+ 2) zurück \newline % Row Count 19 (+ 1) Beispiel: \newline % Row Count 20 (+ 1) SELECT Name, Anrede, Stra{\ss}e, PLZ, Wohnort AS Ort \newline % Row Count 21 (+ 1) FROM Kunde \newline % Row Count 22 (+ 1) UNION \newline % Row Count 23 (+ 1) SELECT Firmenname AS Name, Ansprechpartner, Stra{\ss}e, PLZ, Ort \newline % Row Count 25 (+ 2) FROM Lieferant; \newline % Row Count 26 (+ 1) Bedingungen: Die Spalten der einzelnen Hauptteile müssen miteinander vertr{\"a}glich sein \newline % Row Count 28 (+ 2) (z.B. nicht Zeichenkette versus Zahlenwert). \newline % Row Count 29 (+ 1) Mehrfache Datens{\"a}tze werden automatisch entfernt ("DISTINCT" ist Standardeinstellung). Dies \newline % Row Count 31 (+ 2) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Union / Intersect (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{kann umgangen werden mit "... UNION ALL ..."). Dann werden gleiche Datens{\"a}tze (Tupel) nicht entfernt. \newline % Row Count 3 (+ 3) Schnittmenge (INTERSECT) \newline % Row Count 4 (+ 1) Der Operator INTERSECT gibt nur die Zeilen zurück, \newline % Row Count 6 (+ 2) die aus beiden Abfragen stammen. \newline % Row Count 7 (+ 1) Hiermit kann man z.B. ermitteln welche Adressen \newline % Row Count 8 (+ 1) sowohl in der Kunden als auch in der Adresstabelle \newline % Row Count 10 (+ 2) existieren.% Row Count 11 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{IN / Between}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Operator {\bf{IN}} \newline % Row Count 1 (+ 1) Mit dem Operator {\bf{IN}} l{\"a}sst sich die Bedingung der WHERE-Klausel auch in Form einer Liste \newline % Row Count 3 (+ 2) formulieren. \newline % Row Count 4 (+ 1) Beispiele: \newline % Row Count 5 (+ 1) WHERE Art IN ('Rennrad', 'Tourenrad') \newline % Row Count 6 (+ 1) WHERE Ort IN ('Ulm', 'Biberach') \newline % Row Count 7 (+ 1) Operator {\bf{BETWEEN}} \newline % Row Count 8 (+ 1) Mit dieser Bereichsbedingung in der WHERE-Klausel lassen sich alle Zeilen abrufen, deren \newline % Row Count 10 (+ 2) Spaltenwerte in einem bestimmten Bereich (inkl. der Ober- und Untergrenze) liegen. \newline % Row Count 12 (+ 2) Beispiele: \newline % Row Count 13 (+ 1) WHERE PLZ BETWEEN 86000 AND 86999 \newline % Row Count 14 (+ 1) WHERE Anschaffungspreis BETWEEN 1000 AND 2000% Row Count 15 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{REGEXP}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/penumbragamer_1712657526_Bild_2024-04-09_121203660.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}