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

執(zhí)行按位求和

Performing a bitwise sum(執(zhí)行按位求和)
本文介紹了執(zhí)行按位求和的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

作為復(fù)雜聚合的一部分,我想知道一些數(shù)據(jù)的按位總和,即如果我有值為 1,1,1,2,2,8 的行,按位 sum 是 11.在這種情況下,這些值都是 2 的精確冪(單個位),因此我可以通過對組進行分組和求和來繞過它(顯然,與實際查詢相比,這個示例有點受折磨)):

As part of a complex aggregate I want to know the bitwise sum of some data, i.e. if I have rows with values 1,1,1,2,2,8 the bitwise sum is 11. In this case the values are all exact powers of two (single bits), so I can hack around it by grouping and summing over the groups (obviously this example is a bit tortured compared to the real query):

select SUM(y.test)
from (
    select x.test
    from ( -- garbage test data
        select 1 as [test]
        union all select 1
        union all select 1
        union all select 2
        union all select 2
        union all select 8) x
group by x.test) y

但是有沒有一種干凈的方法可以在 [T]SQL 中執(zhí)行按位求和?

but is there a clean way to perform a bitwise sum in [T]SQL?

推薦答案

如果您的所有測試值都是單個位,如您的示例 (1, 2, 8) - 只需使用 SUM(DISTINCT col) 在您的查詢中.

If all of your test values are single bits as in your example (1, 2, 8) - simply use SUM(DISTINCT col) in your query.

希望有所幫助.

(參考:http://msdn.microsoft.com/en-us/library/ms187810.aspx)

這篇關(guān)于執(zhí)行按位求和的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標(biāo)記轉(zhuǎn)換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計算值創(chuàng)建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 欧美a v在线 | 国产高清精品一区二区三区 | 91福利在线观看 | 中文字幕一区二区三 | 天天看天天爽 | 精品在线一区 | 国产精品高潮呻吟久久 | 在线免费观看视频黄 | 国产伦精品一区二区三区照片91 | 亚洲一区中文字幕 | 国产精品视频网 | 久久久精品视 | 伊人免费在线观看 | 国产一区免费 | 日本在线看| 亚洲福利av| 精品欧美一区二区三区久久久小说 | 久久久.com | 99精品视频在线 | 精品在线一区 | 欧美aa在线 | 97国产一区二区精品久久呦 | 国产精品久久久久久久久久久久 | 亚洲精品视频二区 | 日韩一三区 | 国产精品久久久久久久久久久久午夜片 | 91精品国产91久久综合桃花 | 久久亚洲国产 | 久久国产精品99久久久久 | 亚洲欧美国产一区二区三区 | 97操操| 天堂在线中文 | 日产精品久久久一区二区福利 | 久久精品无码一区二区三区 | 一本色道精品久久一区二区三区 | 欧美日韩亚洲一区 | 国产xxxx在线 | 人人艹人人 | 福利视频网 | 九九热精品在线 | 黄色小视频入口 |