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

相同的查詢給出不同的結(jié)果

Same query giving different results(相同的查詢給出不同的結(jié)果)
本文介紹了相同的查詢給出不同的結(jié)果的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我對(duì)數(shù)據(jù)庫工作還很陌生,所以請(qǐng)耐心等待.我已經(jīng)閱讀了許多類似的問題,但似乎沒有一個(gè)在談?wù)撐颐媾R的同一問題.

I am still new to working in databases, so please have patience with me. I have read through a number of similar questions, but none of them seem to be talking about the same issue I am facing.

只是一些關(guān)于我在做什么的信息,我有一個(gè)填滿聯(lián)系信息的表格,一些聯(lián)系人是重復(fù)的,但大多數(shù)重復(fù)的行都有一個(gè)截?cái)嗟碾娫捥?hào)碼,這使得這些數(shù)據(jù)毫無用處.

Just a bit of info on what I am doing, I have a table filled with contact information, and some of the contacts are duplicated, but most of the duplicated rows have a truncated phone number, which makes that data useless.

我編寫了以下查詢來搜索重復(fù)項(xiàng):

I wrote the following query to search for the duplicates:

WITH CTE (CID, Firstname, lastname, phone, email, length, dupcnt) AS
(
   SELECT 
       CID, Firstname, lastname, phone, email, LEN(phone) AS length,
       ROW_NUMBER() OVER (PARTITION BY Firstname, lastname, email 
                          ORDER BY Firstname) AS dupcnt
   FROM 
       [data.com_raw]
)
SELECT * 
FROM CTE
WHERE dupcnt > 1
  AND length <= 10

我假設(shè)此查詢會(huì)根據(jù)我指定的三列查找所有具有重復(fù)項(xiàng)的記錄,并選擇 dupcnt 大于 1 的任何記錄,以及具有長(zhǎng)度的電話列小于或等于 10.但是當(dāng)我多次運(yùn)行查詢時(shí),每次執(zhí)行都會(huì)得到不同的結(jié)果集.一定有一些我在這里遺漏的邏輯,但我對(duì)此完全感到困惑.所有列都是 varchar 數(shù)據(jù)類型,除了 CID,它是 int.

I assumed that this query would find all records that have duplicates based on the three columns that I have specified, and select any that have the dupcnt greater than 1, and a phone column with a length less than or equal to 10. But when I run the query more than once I get different result sets each execution. There must be some logic that I am missing here, but I am completely baffled by this. All of the columns are of varchar datatype, except for CID, which is int.

推薦答案

代替 ROW_NUMBER() 使用 COUNT(*),并刪除 ORDER BY 因?yàn)槟遣皇潜仨毷褂?COUNT(*).

Instead of ROW_NUMBER() use COUNT(*), and remove the ORDER BY since that's not necessary with COUNT(*).

按照您現(xiàn)在的方式,您正在通過 firstname/lastname/email 將記錄分成相似的記錄組/分區(qū).然后您按 firstname 對(duì)每個(gè)組/分區(qū)進(jìn)行排序.Firstname 是分區(qū)的一部分,這意味著該組/分區(qū)中的每個(gè)名字都是相同的.您將獲得不同的結(jié)果,具體取決于 SQL Server 從存儲(chǔ)中獲取結(jié)果的方式(它首先找到的記錄是 1,第二個(gè)找到的是 2).每次獲取記錄時(shí)(每次運(yùn)行此 sql 時(shí)),它都可能以不同的順序從磁盤或緩存中獲取每條記錄.

The way you have it now, you are chunking up records into similar groups/partitions of records by firstname/lastname/email. Then you are ORDERING each group/partition by firstname. Firstname is part of the partition, meaning every firstname in that group/partition is identical. You will get different results depending on how SQL Server fetches the results from storage (which record it found first is 1, what it found second is 2). Every time it fetches records (every time you run this sql) it may fetch each record from disk or cache at a different order.

Count(*) 將返回所有重復(fù)的行

改為:

 COUNT(*) OVER (PARTITION BY Firstname, lastname, email ) AS dupcnt

這將返回共享相同名字、姓氏和電子郵件的記錄數(shù).然后您保留任何大于 1 的記錄.

Which will return the number of records that share the same firstname, lastname, and email. You then keep any record that is greater than 1.

這篇關(guān)于相同的查詢給出不同的結(jié)果的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個(gè)子標(biāo)記轉(zhuǎn)換為具有多個(gè)分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個(gè)表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計(jì)算值創(chuàng)建計(jì)算值)
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?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對(duì)?) - IT屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(hào)(問題和答案的組合))
主站蜘蛛池模板: 日本三级全黄三级a | 国产乱人伦精品一区二区 | 青青久在线视频 | 久久国产高清 | 亚洲免费观看视频 | 欧美日韩成人网 | 久久综合亚洲 | 香蕉超碰 | 精品成人免费视频 | 国产精品久久久久久久一区二区 | 正在播放国产精品 | 国产一区二区a | 另类专区成人 | av一区二区三区在线观看 | 日本一区二区在线视频 | 美人の美乳で授乳プレイ | 99爱视频 | 国产成人免费视频 | 欧美日韩综合一区 | 日韩中文字幕网 | 久久久www成人免费精品张筱雨 | 中文字幕日韩专区 | 国产99久久精品一区二区永久免费 | 欧美日韩久久精品 | 亚洲综合无码一区二区 | 中文字幕在线免费观看 | av中文在线| www.亚洲区| 欧美大片一区 | 欧美一区二区三区在线观看 | 国产精品一区在线播放 | 91视频久久久久 | 亚洲精品久久久久久久久久久 | 色偷偷噜噜噜亚洲男人 | 国产高清精品一区二区三区 | 欧美日韩精品一区二区三区四区 | 99久久精品免费看国产免费软件 | 午夜一区二区三区视频 | 亚洲欧美高清 | 国产福利91精品一区二区三区 | 国产欧美在线视频 |