Skip to content
Advertisement

Tag: pivot

SQL pivot and group by month

I’m trying to get the sum of production per month and pivot the month row to columns. Could you please tell me what is wrong with this code?’ Answer There were several items wrong in your query. Columns need aliases and your max() within the PIVOT was referencing an invalid column name

How to rotate a two-column table?

This might be a novice question – I’m still learning. I’m on PostgreSQL 9.6 with the following query: My query returns the following dynamic rows: locales count en 10 fr 7 de 3 n additional locales (~300)… n-count I’m trying to rotate it so that locale values end up as columns with a single row, like this: en fr de

Convert rows to columns in SQL Server 2008

We have one table called Licenses. This is what it looks like: CustNum LicenseAddress License ExpiryDate 155 123 Y32CA 12/31/2018 155 998 Y32CB 12/31/2020 155 568 Y32CC 12/31/2022 Here is what I want it to look like: LicAddr1 Lic1 ExpiryDate1 LicAddr2 Lic2 ExpiryDate2 LicAddr3 Lic3 ExpiryDate3 123 Y32CA 12/31/2018 998 Y32CB 12/31/2020 568 Y32CC 12/31/2022 Here is the query I

PIVOT function returning NULL values and ISNULL not removing

I have a query using PIVOT function that has NULL values that wish to replace with 0 in the cell. I have tried to add the ISNULL into the sub query against O7CRAM but that did not remove the NULL values The issue I have now is the ISNULL and where to place it to remove the NULL values. Current

SQL Query for multiple Pivot on same column

As per my requirement, I need to apply pivot twice on same column to get different values as column header. Please see below how the data is present in table and expected results. Table Question Response TranslatedResponse activityid createdon Reason Testing testaus 1 01-01-2022 EMail abc@gmail.com abc@gmail.com 1 01-01-2022 Action test testata 1 01-01-2022 Desired Output : Email Reason Action

Transpose rows to columns using multiple pivots

I am trying to transpose rows to columns without any luck . What I have now WEEK_NUMBER VAL9 VAL4 VAL5 VAL7 45 63.27% 28.58% 7.92% 0.23% 52 65.66% 26.16% 7.80% 0.38% 50 90.97% 8.45% 0.29% 0.29% 46 82.49% 12.43% 3.01% 2.06% 47 66.33% 29.53% 3.77% 0.36% 51 65.36% 31.83% 2.69% 0.11% 49 61.88% 28.29% 9.46% 0.37% 44 45.34% 45.55% 8.45%

PIVOT (without aggregation?) in SQL

I am trying to put together a select statement on some data like the below using TSQL: Table1: Property Detail Record No Surname Smith 1 First Name Anne 1 Title Mrs 1 Gender F 1 Surname Jones 2 First Name Ben 2 Title Mr 2 Gender M 2 Which I am hoping to get results which would appear like this:

converting rows to columns using oracle sql

I’m trying to convert rows into columns using the following sample: LVL COL_VALUE TABLE_SRC 16 INT: ADDRESS_LINE_2:NULL INT 16 BASE: ADDRESS_LINE_2:X BASE 17 INT: ADDRESS_LINE_3:NULL INT 17 BASE: ADDRESS_LINE_3:X BASE The output should be: INT BASE INT: ADDRESS_LINE_2:NULL BASE: ADDRESS_LINE_2:X INT: ADDRESS_LINE_3:NULL BASE: ADDRESS_LINE_3:X The COL_VALUE with the same LVL should be in 1 row I tried using PIVOT but

Advertisement