我正在使用unpivot函数,但它返回的[nulls destination_address]总和小于它从中拉出的视图(2692是正确的)的总和(2293)。因此,坚定不移地将我的结果更改为错误的数字,但我不知道如何解决。我尝试过所有方法,但也无法使其正常工作。
SELECT
[CLIENTDIVISION]
,[SHIP_ACT_PERIOD]
,[DATAFEED_WEEK]
,[BILL_SITE_ID]
,[CARRIERNAME]
--BELOW IS YOUR CATEGORIES
,[TYPE_OF_NULL] --This is a completely new column, does not exits. this is created during an unpivot.
--BELOW IS DATA THAT TIES TO THE CATEGORY.
,[NULLS COUNT] --This is a completely new column, does not exits. this is created during an unpivot.
from [dbo].[BAS_CT_DATA_COMPLETENESS_vw1] --[TABLE HERE]
UNPIVOT
( [NULLS COUNT] for [TYPE_OF_NULL] in
--WHAT YOU PUT IN PIVOT COLUMNS ARE THE CATEGORIES YOU WANT TO PIVOT ON
(
[nulls_INVOICEDBID]
,[nulls_INVOICESHIPMENTDBID]
,[nulls_CLIENTLOCATION]
,[nulls_CLIENTDIVISION]
,[nulls_CARRIERNAME]
,[nulls_INVOICENO]
,[nulls_SID]
,[nulls_SHIPMENTDATE]
,[nulls_PRODUCTION_DATE]
,[nulls_SERVICELEVELCODE]
,[nulls_SERVICELEVELNAME]
,[nulls_ORIGIN_ADDRESS]
,[nulls_ORIGINCITY]
,[nulls_ORIGINCOUNTRYCODE]
,[nulls_SHIPPERPOSTALCODE]
,[nulls_DESTINATION_ADDRESS]
,[nulls_DESTINATIONCITY]
,[nulls_DESTINATIONCOUNTRYCODE]
,[nulls_CONSIGNEEPOSTALCODE]
,[nulls_BILLINGCURRENCY]
,[nulls_INVOICEAMOUNT]
,[nulls_ACCESSORIAL_CODE]
,[nulls_ACCESSORIAL]
,[nulls_ACCESSORIAL_AMOUNT_LOC]
,[nulls_IUOM_CHARGEKILOGRAMS]
,[nulls_REASON_CODE]
,[nulls_REASON_CODE_DESCRIPTION]
,[nulls_GL_CODE]
)) U
GROUP BY
U.[CLIENTDIVISION]
,U.[SHIP_ACT_PERIOD]
,U.[DATAFEED_WEEK]
,U.[BILL_SITE_ID]
,U.[CARRIERNAME]
,U.[TYPE_OF_NULL]
,U.[NULLS COUNT]
GO