久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

要解決的逆向數據場景?

Unpivot Data Scenario to Solve?(要解決的逆向數據場景?)
本文介紹了要解決的逆向數據場景?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

所以我有一張這樣的桌子

So I have a table like this

表一

 Quote Ref | Product A |  Product B  | Product C | Product D
-----------+-----------+-------------+-----------+-----------     
    12     |   222333  |  4748847478 |     0     |     0

我需要使用下表找出這屬于哪個 Business Group.

I need to find out which Business Group this belongs to using the below Table .

我對等于 0 的產品字段不感興趣,因為報價中沒有這些產品,因此沒有要映射的業(yè)務組.對于此報價,產品 A 和 B 列具有非零值并且可以映射到業(yè)務組.(關鍵點)

I am not interested in fields for the Products that equal zero as the quote does not have those products so no Business Group to map . For this quote the Product A and B column have a non zero value and can be mapped to a business group. ( KEY POINT )

表二

Product Line |   Business Group 
Product A    |   Manfacturing 
Product B    | Tech Net

所以我查看表 1 中的 UNPIVOT 數據.

So I look to UNPIVOT data in Table 1 .

SELECT [QUOTE Ref], [Product Line], [Value]

FROM 
   (SELECT [QUOTE Ref], [Product A], [Product B], [Product C], [Product D]

FROM [Table1]) p
UNPIVOT
   ([Value] FOR [Product Line] 
   IN ([Product A], [Product B], [Product C], [Product D] )
)AS unpvt;

表 1 的數據現在像這樣

DATA for table 1 now like this

 Quote Ref | Product Line |   Value
-----------+--------------+------------
    12     |  Product A   |   222333
    12     |  Product B   | 4748847478
    12     |  Product C   |     0 
    12     |  Product D   |     0

問題是現在 4 萬行變成了 470 萬行.

The problem is that 40 k rows NOW becomes 4.7 million rows .

現在我知道我不需要非透視表中 Product Line 值為零的行.如何在 unpivot 查詢中刪除這些條目,或者在啟動 UNPIVOT 之前我可以對基表做些什么?我的數據庫不夠大,無法處理數據庫中大約 20 個類似的表和 60 多萬行.

Now I know I dont need the rows in the unpivoted table where the value for a Product Line equals zero . How can I remove these entries in the unpivot query or is there something I could do to the base table before I even start the UNPIVOT ? My database is nto big enough to cope with about 20 similar tables and 60 extra million rows in the database.

推薦答案

您應該添加條件,以刪除最終結果集中具有 value = 0 的條目.您無法在生成數據的 SELECT 查詢中執(zhí)行此操作,因此將當前結果集作為子查詢括起來,如下所示:

You should add the condition that removes the entries that have value = 0 in the final result set. You couldn't do this in the SELECT query that produces the data, so enclose your current result set as subquery like this:

;WITH Data AS
(
    SELECT [QUOTE Ref], [Product Line], [Value]
    FROM 
    (
        SELECT [QUOTE Ref], [Product A], [Product B], [Product C], [Product D]
        FROM [Table1]
    ) p
    UNPIVOT
       ([Value] FOR [Product Line] 
       IN ([Product A], [Product B], [Product C], [Product D] )
    )AS unpvt
 )
SELECT * 
FROM DATA 
WHERE Value <> 0;

這篇關于要解決的逆向數據場景?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節(jié) [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數據)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
How to convert #39;2016-07-01 01:12:22 PM#39; to #39;2016-07-01 13:12:22#39; hour format?(如何將“2016-07-01 01:12:22 PM轉換為“2016-07-01 13:12:22小時格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
主站蜘蛛池模板: 91精品国产一区二区 | 99免费在线视频 | 97免费视频在线观看 | 羞羞色网站 | 久久久久国产精品一区 | 97国产精品视频 | 午夜精品一区二区三区在线视频 | 日韩精品免费在线 | 一区二区高清在线观看 | 国产区精品视频 | 国产一级特黄aaa大片评分 | 精品久久久久久久 | 中文字幕一区在线 | 久久欧美高清二区三区 | 亚洲精品久久久一区二区三区 | 日日做夜夜爽毛片麻豆 | 91视频18 | 天堂亚洲| 日朝毛片| 久久久婷婷 | 久久久久久国产精品免费免费 | 亚洲一区二区成人 | 亚洲乱码国产乱码精品精的特点 | 成人在线精品视频 | 国产精品久久久久久亚洲调教 | 日韩精品视频在线 | 亚洲一区二区综合 | 亚洲毛片在线 | 综合久久一区 | 91精品国模一区二区三区 | 正在播放国产精品 | 亚洲狠狠爱 | 一区二区三区免费看 | 国产丝袜一区二区三区免费视频 | 美女一级毛片 | 亚洲网站在线播放 | 日本在线精品视频 | 成人午夜激情 | 久久久久精 | 国产欧美一区二区三区免费 | 一区二区三区视频在线观看 |