Q1
True / FalsePostgreSQL has a built-in PIVOT function that can be used directly in SQL queries.
PostgreSQL does not have a built-in PIVOT function like some other databases. Instead, you achieve pivoting by using the crosstab function from the tablefunc extension.
Q2
True / FalseThe crosstab function in PostgreSQL requires the tablefunc extension to be enabled.
The crosstab function, which is used for pivoting data, is part of the tablefunc extension, and you need to enable this extension in your PostgreSQL database.
Q3
True / FalseIn PostgreSQL, the crosstab function can pivot data without specifying the columns in advance.
When using the crosstab function, you must specify the columns in advance, as PostgreSQL needs to know the structure of the output table.
Q4
True / FalseYou can use the crosstab function in PostgreSQL to transform rows into columns based on the values of a specified attribute.
The crosstab function is used to pivot rows into columns based on specified attribute values.
Q5
True / FalseThe first parameter of the crosstab function in PostgreSQL is a SQL query that returns three columns.
The first parameter of the crosstab function in PostgreSQL should return two columns, where the first column is the row identifier and the second column is the value to pivot.
Q6
True / FalseIn PostgreSQL, you can use window functions as an alternative to pivoting data when using crosstab is not suitable.
Window functions in PostgreSQL can be used to perform complex aggregations and calculations over a set of rows, which can sometimes serve as an alternative to pivoting data
Q7
True / FalseIn PostgreSQL, the crosstab function can only handle a fixed number of pivot columns, which must be known beforehand.
The crosstab function requires that the number of pivot columns be specified in advance, as it needs to know the structure of the result set.
Q8
True / FalseTo dynamically pivot data in PostgreSQL without knowing the column names in advance, you can use dynamic SQL and procedural code.
Dynamic SQL combined with procedural code (e.g., PL/pgSQL) can be used to create a pivot table dynamically when the column names are not known in advance.
Q9
True / FalseThe crosstab function in PostgreSQL can be used in conjunction with the GROUP BY clause to aggregate data before pivoting.
The crosstab function itself handles the aggregation of data for pivoting, so it is used instead of the GROUP BY clause.
Q10
True / FalsePostgreSQL provides a built-in function called pivot_table for easily transforming row data into columns.
PostgreSQL does not have a built-in pivot_table function. Pivoting is done using the crosstab function from the tablefunc extension, which requires some setup and predefined column structure.
Q14
Single ChoiceWhich crosstab query will PIVOT this data to show products as columns?
SQL Code
month product amount
Jan A 100
Jan B 150
Feb A 200
Feb B 250
The crosstab function requires the input query to be ordered by the first column (row header) and the second column (category header).
Q15
Single ChoiceWhat will be the output columns when using the crosstab function on the following query in PostgreSQL?
SQL Code
SELECT * FROM crosstab('SELECT month, product, amount FROM sales ORDER BY 1,2')
AS ct(month text, A int, B int);
The output columns correspond to the row identifier (month) and the unique categories (A, B).
Q17
Single ChoiceWhich crosstab query will PIVOT this data to include only the months "Jan" and "Feb" as row headers and "A" and "B" as columns?
SQL Code
month product amount
Jan A 100
Jan B 150
Feb A 200
Feb B 250
Mar A 300
Mar B 350
Both queries correctly filter the data and order it for the crosstab function, producing the desired PIVOT output.
Q20
Single ChoiceHow would you write a crosstab query in PostgreSQL to PIVOT this data by month as row headers and product as columns, with a dynamically generated column list?
SQL Code
month product amount
Jan A 100
Jan B 150
Feb A 200
Feb B 250
Mar A 300
Mar B 350
Apr A 400
Apr B 450
In PostgreSQL, you must define the output columns explicitly, as in this correct query, where the row header is month and the columns are A and B.
Q21
Multiple ChoiceWhich SQL queries correctly use the PIVOT functionality in PostgreSQL to transform data?
PostgreSQL does not have a direct PIVOT operator like some other databases, but the same result can be achieved using conditional aggregation and CASE statements.
Q22
Multiple ChoiceIdentify the SQL queries that correctly apply PIVOT-like transformations using conditional aggregation in PostgreSQL.
In PostgreSQL, pivot-like functionality can be achieved using conditional aggregation with CASE statements. This approach allows you to transform row data into columns.
Q23
Multiple ChoiceWhich SQL queries correctly use the PIVOT-like functionality in PostgreSQL to summarize data?
To achieve PIVOT-like transformations in PostgreSQL, you can use CASE statements within an aggregation function to conditionally summarize data based on the desired columns.
Q24
Multiple ChoiceDetermine the SQL queries that correctly implement PIVOT-like transformations for attendance records in PostgreSQL.
To implement PIVOT-like transformations in PostgreSQL, use conditional aggregation to rotate row data into columns based on specific criteria, such as days of the week.
Q25
Multiple ChoiceIdentify the SQL queries that correctly use PIVOT-like functionality to transform and aggregate sales data in PostgreSQL.
In PostgreSQL, you can simulate a PIVOT by using CASE statements with aggregation to convert rows into columns based on specific conditions, such as quarters.
Q26
Multiple ChoiceWhich SQL queries correctly use PIVOT-like functionality in PostgreSQL for financial data transformation?
To pivot financial data in PostgreSQL, use conditional aggregation with CASE statements, converting rows into columns based on the month.
Q27
Multiple ChoiceDetermine the SQL queries that correctly implement PIVOT-like transformations for project management data in PostgreSQL.
In PostgreSQL, PIVOT-like functionality can be achieved by using conditional aggregation to transform row data into columns based on the week.
Q28
Multiple ChoiceWhich SQL queries correctly use PIVOT-like functionality to transform and aggregate survey data in PostgreSQL?
To achieve PIVOT-like transformations in PostgreSQL, you can use CASE statements within an aggregation function to conditionally summarize data by question.
Q29
Multiple ChoiceIdentify the SQL queries that correctly use PIVOT-like functionality in PostgreSQL for employee shift data.
In PostgreSQL, you can use conditional aggregation with CASE statements to create a PIVOT-like effect, transforming rows into columns based on the day of the week.
Q30
Multiple ChoiceWhich SQL queries correctly use PIVOT-like functionality in PostgreSQL for customer order data?
To pivot order data in PostgreSQL, use conditional aggregation with CASE statements, converting rows into columns based on the quarter.