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

查詢周報

Query for weekly report(查詢周報)
本文介紹了查詢周報的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我目前正在編寫查詢以生成每周一到下周日的每周報告.

I am currently writing a query to generate a weekly report from every Monday to the next Sunday.

SELECT top 10 
 DATEADD(WEEK, DATEDIFF(WEEK, '19000101', mydatefield), '19000101') as EveryMonday, 
 DATEADD(WEEK, DATEDIFF(WEEK, '19000101', mydatefield)+1, '19000101')-1 as EverySunday, count(items)
FROM myitemtable
GROUP BY 
 DATEADD(WEEK, DATEDIFF(WEEK, '19000101', mydatefield), '19000101') as EveryMonday, 
 DATEADD(WEEK, DATEDIFF(WEEK, '19000101', mydatefield)+1, '19000101')-1 as EverySunday    

對比

SELECT count(items)
FROM myitemtable
WHERE mydatefield >= '2011/05/30 00.00.000' and mydatefield <= '2011/06/05 23.59.59' 

上面的查詢有什么問題.第一個和第二個查詢中的計數(shù)加起來是不同的數(shù)字.

What is wrong with the above query. The counts add up to a different number in the first and second queries.

推薦答案

在沒有特別理解查詢的情況下(因為我通常使用比 tsql 使用的更標準的 SQL 變體編寫),我在查看查詢時的直覺反應(yīng)是這可能是時區(qū)問題.但是,您需要做的是驗證您得到的答案是否符合您的預(yù)期.為此,請運行:

Without particularly understanding the query (since I normally write in a far more standard variant of SQL than tsql uses), my gut reaction when looking at your query was that this could be a timezone problem. But, what you need to do is verify the answers you are getting are what you expect. To do this, run:

SELECT mydatefield,
 DATEADD(WEEK, DATEDIFF(WEEK, '19000101', mydatefield), '19000101') as EveryMonday, 
 DATEADD(WEEK, DATEDIFF(WEEK, '19000101', mydatefield)+1, '19000101')-1 as EverySunday
FROM myitemtable
WHERE mydatefield >= '2011/05/30 00.00.000' and mydatefield <= '2011/06/05 23.59.59'

如果這是太多數(shù)據(jù),這里有另一種選擇:

if this is too much data, here is another option:

SELECT min(mydatefield),max(mydatefield),count(*),
 DATEADD(WEEK, DATEDIFF(WEEK, '19000101', mydatefield), '19000101') as EveryMonday, 
 DATEADD(WEEK, DATEDIFF(WEEK, '19000101', mydatefield)+1, '19000101')-1 as EverySunday
FROM myitemtable
WHERE mydatefield >= '2011/05/30 00.00.000' and mydatefield <= '2011/06/05 23.59.59'
GROUP BY 
 DATEADD(WEEK, DATEDIFF(WEEK, '19000101', mydatefield), '19000101') as EveryMonday, 
 DATEADD(WEEK, DATEDIFF(WEEK, '19000101', mydatefield)+1, '19000101')-1 as EverySunday

及相關(guān):

SELECT min(mydatefield),max(mydatefield),count(*),
 DATEADD(WEEK, DATEDIFF(WEEK, '19000101', mydatefield), '19000101') as EveryMonday, 
 DATEADD(WEEK, DATEDIFF(WEEK, '19000101', mydatefield)+1, '19000101')-1 as EverySunday
FROM myitemtable
GROUP BY 
 DATEADD(WEEK, DATEDIFF(WEEK, '19000101', mydatefield), '19000101') as EveryMonday, 
 DATEADD(WEEK, DATEDIFF(WEEK, '19000101', mydatefield)+1, '19000101')-1 as EverySunday

運行這些查詢應(yīng)該可以幫助您了解EveryMonday"和EverySunday"查詢是否生成了您期望的值.查看最小/最大日期將有助于您了解何時發(fā)生不匹配.

Running these queries should help you understand if the "EveryMonday" and "EverySunday" queries are generating the values you expect. Seeing the min/max dates will help you understand when the mismatches are occurring.

這篇關(guān)于查詢周報的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)(將每個子標記轉(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)換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 国产在线观看av | 亚洲精品一区中文字幕乱码 | 欧美不卡视频 | 久久久久久久久久久久久久av | 日韩电影免费在线观看中文字幕 | 国产一区二区在线播放 | 精品欧美二区 | av天天干| 国产精品69av | 成人精品国产免费网站 | 区一区二在线观看 | 欧美一级黄色片在线观看 | 91国产精品| 一区二区三区视频在线 | 久久爱一区 | 日日天天| 国产成人艳妇aa视频在线 | 狠狠干2020 | 久久精品伊人 | 中文字幕不卡在线观看 | 亚洲人成人网 | 又黄又爽的网站 | 欧美精品久久久久久 | 久久精彩 | 毛片软件 | 亚洲精品乱码久久久久久蜜桃91 | 国产成人在线一区二区 | 激情一区二区三区 | 99精品在线| 中文日韩在线 | 伊人婷婷 | 久久久999免费视频 999久久久久久久久6666 | 成人精品一区二区 | 一区二区三区四区在线视频 | 天天综合日日夜夜 | 欧美综合在线观看 | 天天插日日操 | 一区二区在线不卡 | 国产日韩精品一区二区 | www.99re | 九九综合 |