
Zuerst habe ich versucht, eine Tabelle nach normalen Maßstäben zu erstellen:
\begin{table}[H]
\centering
\begin{tabular}{p{14cm}|c}
\textit{Query} & Grupo \\
\hline
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_yearmonthnum = 199401 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 4 AND 6 AND lo\_quantity BETWEEN 26 AND 35; & 1 \\
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_year = 1993 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 1 AND 3 AND lo\_quantity < 25; & 1 \\
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_weeknuminyear = 6 AND lo\_orderdate = d\_datekey AND d\_year = 1994 AND lo\_discount BETWEEN 5 AND 7 AND lo\_quantity BETWEEN 26 AND 35; & 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_category = 'MFGR\#12' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'AMERICA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand; & 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand BETWEEN 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND 'MFGR\#2228' AND s\_region = 'ASIA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand; & 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand = 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'EUROPE' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand; & 1 \\
SELECT c\_nation, s\_nation, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND c\_region = 'ASIA' AND s\_region = 'ASIA' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_nation, s\_nation, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE c\_nation = 'UNITED STATES' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND s\_nation = 'UNITED STATES' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_year >= 1992 AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_yearmonth = 'Dec1997' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT d\_year, c\_nation, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, c\_nation ORDER BY d\_year, c\_nation; & 1 \\
SELECT d\_year, s\_nation, p\_category, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (d\_year = 1997 OR d\_year = 1998) AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, s\_nation, p\_category ORDER BY d\_year, s\_nation, p\_category; & 1 \\
SELECT d\_year, s\_city, p\_brand, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_nation = 'UNITED STATES' AND (d\_year = 1997 OR d\_year = 1998) AND p\_category = 'MFGR\#14' GROUP BY d\_year, s\_city, p\_brand ORDER BY d\_year, s\_city, p\_brand; & 1 \\
\end{tabular}
\caption{Classificação das \textit{queries} do \gls{ssb}}
\label{tab:ssb_queries}
\end{table}
Der obige Code bereitet mir zwei Probleme: Er passt nicht auf eine oder mehrere Seiten und der Inhalt der zweiten Spalte ist nicht vertikal ausgerichtet. Also habe ich versucht, longtable
stattdessen Folgendes zu verwenden table
:
\begin{center}
\begin{longtable}{p{14cm}|c}
\textit{Query} & Group \\
\hline
\endfirsthead
\textit{Query} & Group \\
\hline
\endhead
\hline
\multicolumn{2}{l}{Continue\ldots} \\
\endfoot
\hline
\multicolumn{2}{l}{End} \\
\endlastfoot
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_yearmonthnum = 199401 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 4 AND 6 AND lo\_quantity BETWEEN 26 AND 35; & 1 \\
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_year = 1993 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 1 AND 3 AND lo\_quantity < 25; & 1 \\
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_weeknuminyear = 6 AND lo\_orderdate = d\_datekey AND d\_year = 1994 AND lo\_discount BETWEEN 5 AND 7 AND lo\_quantity BETWEEN 26 AND 35; & 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_category = 'MFGR\#12' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'AMERICA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand; & 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand BETWEEN 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND 'MFGR\#2228' AND s\_region = 'ASIA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand; & 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand = 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'EUROPE' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand; & 1 \\
SELECT c\_nation, s\_nation, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND c\_region = 'ASIA' AND s\_region = 'ASIA' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_nation, s\_nation, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE c\_nation = 'UNITED STATES' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND s\_nation = 'UNITED STATES' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_year >= 1992 AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_yearmonth = 'Dec1997' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC; & 1 \\
SELECT d\_year, c\_nation, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, c\_nation ORDER BY d\_year, c\_nation; & 1 \\
SELECT d\_year, s\_nation, p\_category, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (d\_year = 1997 OR d\_year = 1998) AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, s\_nation, p\_category ORDER BY d\_year, s\_nation, p\_category; & 1 \\
SELECT d\_year, s\_city, p\_brand, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_nation = 'UNITED STATES' AND (d\_year = 1997 OR d\_year = 1998) AND p\_category = 'MFGR\#14' GROUP BY d\_year, s\_city, p\_brand ORDER BY d\_year, s\_city, p\_brand; & 1 \\
\caption{Classificação das \textit{queries} do \gls{ssb}} \\
\end{longtable}
\end{center}
Der zweite Code platziert die lange Tabelle über mehrere Seiten, aber die Überschrift der Tabelle befindet sich im Fußteil. Wie kann ich die zweite Spalte vertikal zentrieren, die Überschrift unten platzieren und die Tabelle auf eine oder mehrere Seiten bringen? Ist es außerdem möglich, Abstände zwischen den Zeilen hinzuzufügen?
BEARBEITEN:
Die von mir verwendete Vorlage finden SieHier.
Antwort1
longtable
Hier ist ein Code, der auf funktionierenden Kopf- und Fußzeilen basiert . Ich habe auch zwei Pakete hinzugefügt: listings
verbessert die Codeformatierung und cellspace
fügt zusätzlichen vertikalen Abstand zwischen den Zeilen ein.
\documentclass{article}
\usepackage{array}
\usepackage{xcolor}
\usepackage[margin=1in]{geometry}
\usepackage{listings}
\usepackage{longtable}
\usepackage[column=E]{cellspace}
\lstset{
basicstyle=\small\rmfamily, % \ttfamily or \sffamily
aboveskip=0pt,
belowskip=0pt,
boxpos=t,
language=sql,
keywordstyle=\color{black!30!blue}\bfseries,
columns=flexible,
}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\begin{document}
\begin{longtable}{E{w{l}{12cm}}|c}
\caption{Classificação das \textit{queries} do SSB}\label{tab:ssb_queries} \\
% \caption{Classificação das \textit{queries} do \gls{ssb}}
\textit{Query} & Group \\
\hline\endfirsthead
\textit{Query} & Group \\
\hline\endhead
\hline
\multicolumn{2}{@{}E{l}}{Continue ...}\endfoot
\hline
\multicolumn{2}{@{}E{l}}{End.}\endlastfoot
%%%
\begin{lstlisting}
SELECT SUM(lo_extendedprice*lo_discount) AS revenue
FROM lineorder, dwdate
WHERE d_yearmonthnum = 199401
AND lo_orderdate = d_datekey
AND lo_discount BETWEEN 4
AND 6 AND lo_quantity
BETWEEN 26 AND 35;
\end{lstlisting} & 1 \\
\begin{lstlisting}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d_year = 1993
AND lo_orderdate = d\_datekey
AND lo_discount
BETWEEN 1 AND 3
AND lo_quantity < 25;
\end{lstlisting} & 1 \\
\begin{lstlisting}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d_year = 1993
AND lo_orderdate = d\_datekey
AND lo_discount
BETWEEN 1 AND 3
AND lo_quantity < 25;
\end{lstlisting} & 1 \\
\begin{lstlisting}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d_year = 1993
AND lo_orderdate = d\_datekey
AND lo_discount
BETWEEN 1 AND 3
AND lo_quantity < 25;
\end{lstlisting} & 1 \\
\begin{lstlisting}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d_year = 1993
AND lo_orderdate = d\_datekey
AND lo_discount
BETWEEN 1 AND 3
AND lo_quantity < 25;
\end{lstlisting} & 1 \\
\begin{lstlisting}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d_year = 1993
AND lo_orderdate = d\_datekey
AND lo_discount
BETWEEN 1 AND 3
AND lo_quantity < 25;
\end{lstlisting} & 1 \\
\begin{lstlisting}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d_year = 1993
AND lo_orderdate = d\_datekey
AND lo_discount
BETWEEN 1 AND 3
AND lo_quantity < 25;
\end{lstlisting} & 1 \\
\begin{lstlisting}
SELECT SUM(lo_extendedprice*lo_discount) AS revenue
FROM lineorder, dwdate
WHERE d_yearmonthnum = 199401
AND lo_orderdate = d_datekey
AND lo_discount BETWEEN 4
AND 6 AND lo_quantity
BETWEEN 26 AND 35;
\end{lstlisting} & 1 \\
\end{longtable}
\end{document}
BEARBEITEN. Wenn Sie eine andere vertikale Ausrichtung bevorzugen, ändern Sie einfach den Wert von boxpos
. Ich habe beispielsweise m
für die mittlere Ausrichtung Folgendes angenommen:
\lstset{
% ...
boxpos=m, % t for top or b for bottom alignment
% ...
}
Ich bin auch davon ausgegangen, dass Sie den Titel auf der letzten Seite unten in Ihrer Tabelle erwarten würden. Sie müssen sowohl als auch in einen Block verschieben, der \caption
mit \label
endet \endlastfoot
. Unten ist der Ausschnitt:
% ...
\begin{longtable}{E{w{l}{12cm}}|c}
\textit{Query} & Group \\
\hline\endfirsthead
\textit{Query} & Group \\
\hline\endhead
\hline
\multicolumn{2}{@{}E{l}}{Continue ...}\endfoot
\hline
\multicolumn{2}{@{}E{l}}{End.} \\[2ex]
\caption{Classificação das \textit{queries} do SSB}
\label{tab:ssb_queries}\endlastfoot
%%%
% ...
Der Rest des Codes bleibt gleich.
Antwort2
Hier ist eine longtable
Lösung, die versucht, der Tabelle ein offeneres „Aussehen“ zu verleihen, indem die Linienzeichnungsmakros des booktabs
Pakets verwendet werden – insbesondere , \midrule
, \addlinespace
und \bottomrule
– anstelle von \hline
. Außerdem wird auf die vollständige Blocksatzausrichtung verzichtet.
\documentclass{article}
\usepackage[a4paper,margin=2.5cm]{geometry} % set page parameters as needed
\usepackage[portuguese]{babel}
\usepackage[T1]{fontenc}
\providecommand\gls[1]{#1} % ??
% new:
\usepackage{longtable,array,booktabs}
\begin{document}
\begin{longtable}{@{} >{\raggedright\arraybackslash}p{14cm} r @{}}
%% headers and footers
\caption{Classificação das \textit{queries} do \gls{ssb}} \\
\textit{Query} & Group \\
\midrule
\endfirsthead
\tablename\ \thetable, continued\\[1ex]
\textit{Query} & Group \\
\midrule
\endhead
\midrule
\multicolumn{2}{r@{}}{Continue\dots} \\
\endfoot
\bottomrule
%\multicolumn{2}{l}{End} \\
\endlastfoot
%% body of longtable
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_yearmonthnum = 199401 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 4 AND 6 AND lo\_quantity BETWEEN 26 AND 35;
& 1 \\
\addlinespace
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_year = 1993 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 1 AND 3 AND lo\_quantity < 25;
& 1 \\
\addlinespace
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_weeknuminyear = 6 AND lo\_orderdate = d\_datekey AND d\_year = 1994 AND lo\_discount BETWEEN 5 AND 7 AND lo\_quantity BETWEEN 26 AND 35;
& 1 \\
\addlinespace
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_category = 'MFGR\#12' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'AMERICA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand;
& 1 \\
\addlinespace
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand BETWEEN 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND 'MFGR\#2228' AND s\_region = 'ASIA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand;
& 1 \\
\addlinespace
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand = 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'EUROPE' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand;
& 1 \\
\addlinespace
SELECT c\_nation, s\_nation, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND c\_region = 'ASIA' AND s\_region = 'ASIA' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_nation, s\_nation, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
\addlinespace
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE c\_nation = 'UNITED STATES' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND s\_nation = 'UNITED STATES' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
\addlinespace
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_year >= 1992 AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
\addlinespace
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_yearmonth = 'Dec1997' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
\addlinespace
SELECT d\_year, c\_nation, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, c\_nation ORDER BY d\_year, c\_nation;
& 1 \\
\addlinespace
SELECT d\_year, s\_nation, p\_category, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (d\_year = 1997 OR d\_year = 1998) AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, s\_nation, p\_category ORDER BY d\_year, s\_nation, p\_category;
& 1 \\
\addlinespace
SELECT d\_year, s\_city, p\_brand, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_nation = 'UNITED STATES' AND (d\_year = 1997 OR d\_year = 1998) AND p\_category = 'MFGR\#14' GROUP BY d\_year, s\_city, p\_brand ORDER BY d\_year, s\_city, p\_brand;
& 1 \\
\end{longtable}
\end{document}
Antwort3
Versuchen Sie es mit longtblr
dem tabularray
Paket. Die Verwendung von MWE ist viel kürzer und klarer:
\documentclass{article}
\usepackage{geometry}
\usepackage{tabularray}
\begin{document}
\begin{longtblr}[
caption = {Classificação das \textit{queries} do},% \gls{ssb}
label = {longtab:?}
]{hline{2,Z} = {solid}, vline{2} = solid,
colspec = {X[j] c},
rowsep=3pt,
rowhead = 1
}
\textit{Query}
& Group \\
%%%% table body
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_yearmonthnum = 199401 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 4 AND 6 AND lo\_quantity BETWEEN 26 AND 35;
& 1 \\
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_year = 1993 AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 1 AND 3 AND lo\_quantity < 25;
& 1 \\
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue FROM lineorder, dwdate WHERE d\_weeknuminyear = 6 AND lo\_orderdate = d\_datekey AND d\_year = 1994 AND lo\_discount BETWEEN 5 AND 7 AND lo\_quantity BETWEEN 26 AND 35;
& 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_category = 'MFGR\#12' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'AMERICA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand;
& 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand BETWEEN 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND 'MFGR\#2228' AND s\_region = 'ASIA' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand;
& 1 \\
SELECT SUM(lo\_revenue), d\_year, p\_brand FROM lineorder, dwdate, part, supplier WHERE p\_brand = 'MFGR\#2221' AND lo\_orderdate = d\_datekey AND lo\_partkey = p\_partkey AND lo\_suppkey = s\_suppkey AND s\_region = 'EUROPE' GROUP BY d\_year, p\_brand ORDER BY d\_year, p\_brand;
& 1 \\
SELECT c\_nation, s\_nation, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND c\_region = 'ASIA' AND s\_region = 'ASIA' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_nation, s\_nation, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE c\_nation = 'UNITED STATES' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND s\_nation = 'UNITED STATES' AND d\_year >= 1992 AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_year >= 1992 AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') AND d\_year <= 1997 GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
SELECT c\_city, s\_city, d\_year, SUM(lo\_revenue) AS revenue FROM customer, lineorder, supplier, dwdate WHERE d\_yearmonth = 'Dec1997' AND lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_orderdate = d\_datekey AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5') AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5') GROUP BY c\_city, s\_city, d\_year ORDER BY d\_year asc, revenue DESC;
& 1 \\
SELECT d\_year, c\_nation, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, c\_nation ORDER BY d\_year, c\_nation;
& 1 \\
SELECT d\_year, s\_nation, p\_category, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_region = 'AMERICA' AND (d\_year = 1997 OR d\_year = 1998) AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2') GROUP BY d\_year, s\_nation, p\_category ORDER BY d\_year, s\_nation, p\_category;
& 1 \\
SELECT d\_year, s\_city, p\_brand, SUM(lo\_revenue - lo\_supplycost) AS profit FROM dwdate, customer, supplier, part, lineorder WHERE lo\_custkey = c\_custkey AND lo\_suppkey = s\_suppkey AND lo\_partkey = p\_partkey AND lo\_orderdate = d\_datekey AND c\_region = 'AMERICA' AND s\_nation = 'UNITED STATES' AND (d\_year = 1997 OR d\_year = 1998) AND p\_category = 'MFGR\#14' GROUP BY d\_year, s\_city, p\_brand ORDER BY d\_year, s\_city, p\_brand;
& 1 \\
\end{longtblr}
\end{document}
Antwort4
Die Antwort von @Celdor ist sehr interessant, deshalb versuche ich, seinen Ansatz in meiner Antwort umzusetzen. Mir wurde schnell klar, dass dies nicht so einfach ist, da Listen nicht direkt in tabularray
Zellen eingefügt werden können, selbst wenn Sie verb
die Option verwenden (es werden nur Kurzbefehle unterstützt \verb
).
Mit Hilfe von @Paul GaboritAntwortZu meiner Hilfeanfrage finden Sie unten eine mögliche Lösung für Ihr Problem:
\documentclass{article}
\usepackage{tabularray}
\usepackage{xcolor}
\usepackage{listings}
\lstset{
basicstyle=\small\sffamily,
aboveskip=-7pt,
belowskip=-2pt,
language=sql,
keywordstyle=\color{black!30!blue}\bfseries,
columns=flexible,
}
\begin{document}
\begin{filecontents*}[force]{\jobname-sql-1.tex}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d\_yearmonthnum = 199401
AND lo\_orderdate = d\_datekey AND lo\_discount BETWEEN 4
AND 6
AND lo\_quantity BETWEEN 26 AND 35;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-2.tex}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue F
ROM lineorder, dwdate
WHERE d\_year = 1993
AND lo\_orderdate = d\_datekey
AND lo\_discount BETWEEN 1
AND 3
AND lo\_quantity < 25;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-3.tex}
SELECT SUM(lo\_extendedprice*lo\_discount) AS revenue
FROM lineorder, dwdate
WHERE d\_weeknuminyear = 6
AND lo\_orderdate = d\_datekey
AND d\_year = 1994
AND lo\_discount BETWEEN 5
AND 7
AND lo\_quantity BETWEEN 26 AND 35;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-4.tex}
SELECT SUM(lo\_revenue), d\_year, p\_brand
FROM lineorder, dwdate, part, supplier
WHERE p\_category = 'MFGR\#12'
AND lo\_orderdate = d\_datekey
AND lo\_partkey = p\_partkey
AND lo\_suppkey = s\_suppkey
AND s\_region = 'AMERICA'
GROUP BY d\_year, p\_brand
ORDER BY d\_year, p\_brand;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-5.tex}
SELECT SUM(lo\_revenue), d\_year, p\_brand
FROM lineorder, dwdate, part, supplier
WHERE p\_brand BETWEEN 'MFGR\#2221'
AND lo\_orderdate = d\_datekey
AND lo\_partkey = p\_partkey
AND lo\_suppkey = s\_suppkey
AND 'MFGR\#2228' AND s\_region = 'ASIA'
GROUP BY d\_year, p\_brand
ORDER BY d\_year, p\_brand;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-6.tex}
SELECT SUM(lo\_revenue), d\_year, p\_brand
FROM lineorder, dwdate, part, supplier
WHERE p\_brand = 'MFGR\#2221'
AND lo\_orderdate = d\_datekey
AND lo\_partkey = p\_partkey
AND lo\_suppkey = s\_suppkey
AND s\_region = 'EUROPE'
GROUP BY d\_year, p\_brand
ORDER BY d\_year, p\_brand;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-7.tex}
SELECT c\_nation, s\_nation, d\_year,
SUM(lo\_revenue) AS revenue
FROM customer, lineorder, supplier, dwdate
WHERE lo\_custkey = c\_custkey
AND lo\_suppkey = s\_suppkey
AND lo\_orderdate = d\_datekey
AND c\_region = 'ASIA'
AND s\_region = 'ASIA'
AND d\_year >= 1992
AND d\_year <= 1997
GROUP BY c\_nation, s\_nation, d\_year
ORDER BY d\_year asc, revenue DESC;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-8.tex}
SELECT c\_city, s\_city, d\_year,
SUM(lo\_revenue) AS revenue
FROM customer, lineorder, supplier, dwdate
WHERE c\_nation = 'UNITED STATES'
AND lo\_custkey = c\_custkey
AND lo\_suppkey = s\_suppkey
AND lo\_orderdate = d\_datekey
AND s\_nation = 'UNITED STATES'
AND d\_year >= 1992
AND d\_year <= 1997
GROUP BY c\_city, s\_city, d\_year
ORDER BY d\_year asc, revenue DESC;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-9.tex}
SELECT c\_city, s\_city, d\_year,
SUM(lo\_revenue) AS revenue
FROM customer, lineorder, supplier, dwdate
WHERE d\_year >= 1992
AND lo\_custkey = c\_custkey
AND lo\_suppkey = s\_suppkey
AND lo\_orderdate = d\_datekey
AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5')
AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5')
AND d\_year <= 1997
GROUP BY c\_city, s\_city, d\_year
ORDER BY d\_year asc, revenue DESC;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-10.tex}
SELECT c\_city, s\_city, d\_year,
SUM(lo\_revenue) AS revenue
FROM customer, lineorder, supplier, dwdate
WHERE d\_yearmonth = 'Dec1997'
AND lo\_custkey = c\_custkey
AND lo\_suppkey = s\_suppkey
AND lo\_orderdate = d\_datekey
AND (c\_city='UNITED KI1' OR c\_city='UNITED KI5')
AND (s\_city='UNITED KI1' OR s\_city='UNITED KI5')
GROUP BY c\_city, s\_city, d\_year
ORDER BY d\_year asc, revenue DESC;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-11.tex}
SELECT d\_year, c\_nation,
SUM(lo\_revenue - lo\_supplycost) AS profit
FROM dwdate, customer, supplier, part, lineorder
WHERE lo\_custkey = c\_custkey
AND lo\_suppkey = s\_suppkey
AND lo\_partkey = p\_partkey
AND lo\_orderdate = d\_datekey
AND c\_region = 'AMERICA'
AND s\_region = 'AMERICA'
AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2')
GROUP BY d\_year, c\_nation
ORDER BY d\_year, c\_nation;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-12.tex}
SELECT d\_year, s\_nation, p\_category,
SUM(lo\_revenue - lo\_supplycost) AS profit
FROM dwdate, customer, supplier, part, lineorder
WHERE lo\_custkey = c\_custkey
AND lo\_suppkey = s\_suppkey
AND lo\_partkey = p\_partkey
AND lo\_orderdate = d\_datekey
AND c\_region = 'AMERICA'
AND s\_region = 'AMERICA'
AND (d\_year = 1997 OR d\_year = 1998)
AND (p\_mfgr = 'MFGR\#1' OR p\_mfgr = 'MFGR\#2')
GROUP BY d\_year, s\_nation, p\_category
ORDER BY d\_year, s\_nation, p\_category;
\end{filecontents*}\\
\begin{filecontents*}[force]{\jobname-sql-13.tex}
SELECT d\_year, s\_city, p\_brand,
SUM(lo\_revenue - lo\_supplycost) AS profit
FROM dwdate, customer, supplier, part, lineorder
WHERE lo\_custkey = c\_custkey
AND lo\_suppkey = s\_suppkey
AND lo\_partkey = p\_partkey
AND lo\_orderdate = d\_datekey
AND c\_region = 'AMERICA'
AND s\_nation = 'UNITED STATES'
AND (d\_year = 1997 OR d\_year = 1998)
AND p\_category = 'MFGR\#14'
GROUP BY d\_year, s\_city, p\_brand
ORDER BY d\_year, s\_city, p\_brand;
\end{filecontents*}\\
\noindent%
\begin{longtblr}[
caption = {Classificação das \textit{queries} do},% \gls{ssb}
label = {longtab:?}
]{hline{2,Z} = {solid},
colspec = {X[j,m] | c},
row{1} = {font=\itshape},
rowsep=0pt,
rowhead=1}
rowhead=1}
\lstinputlisting{\jobname-sql-1.tex} & 1 \\
\lstinputlisting{\jobname-sql-2.tex} & 1 \\
\lstinputlisting{\jobname-sql-3.tex} & 1 \\
\lstinputlisting{\jobname-sql-4.tex} & 1 \\
\lstinputlisting{\jobname-sql-5.tex} & 1 \\
\lstinputlisting{\jobname-sql-6.tex} & 1 \\
\lstinputlisting{\jobname-sql-7.tex} & 1 \\
\lstinputlisting{\jobname-sql-8.tex} & 1 \\
\lstinputlisting{\jobname-sql-9.tex} & 1 \\
\lstinputlisting{\jobname-sql-10.tex} & 1 \\
\lstinputlisting{\jobname-sql-11.tex} & 1 \\
\lstinputlisting{\jobname-sql-12.tex} & 1 \\
\lstinputlisting{\jobname-sql-13.tex} & 1 \\
\end{longtblr}
\end{document}