写查询以获取名称“paul D ottaway” [英] Write query to fetch name "paul D ottaway"
问题描述
SID NAME COMPLETED_YEAR COMPLETED_MONTH COMPLETED_MONTH_NAME TOTAL_COUNT
N060698 Paul D Ottaway 2016 5月7日
N060698 Paul D Ottaway 2016 6月17日
N060698 Paul D Ottaway 2016 7月7日
N060698 Paul D Ottaway 2016 8月22日
N060698 Paul Ottaway 2016 8月3日
N060698 Paul D Ottaway 2016 9月16日
N060698 Paul Ottaway 2016 9月19日
N060698 Paul D Ottaway 2016 10月10日
N060698 Paul Ottaway 2016 10月10日
以上是表输入。
我想获取其中name =Paul D Ottaway的记录和8月份的总数= 22 + 3 = 25作为一条记录。
输出我想要如下我只拿了名字=Paul D Ottaway
N060698 Paul D Ottaway 2016 5月7日
N060698 Paul D Ottaway 2016 6月17日
N060698 Paul D Ottaway 2016 7月7日
N060698 Paul D Ottaway 2016 8月25日
N060698 Paul D Ottaway 2016 9月35日
N060698 Paul D Ottaway 2016 10月10日
我尝试了什么:
我试图用计数和总和来检索。
请帮我这个。试试:
SELECT [Name],SUM(Total_Count) AS TotalCount FROM MyTable
WHERE SID = ' N060698'
GROUP BY [名称] ],Complete_Month
Quote:写入查询以获取名称paul D ottaway
您是否看到您的示例无法使用paul D ottaway这个名称来获得所需的结果,因为8月的第二行不是这个名字?
解决方案可能看起来像是OriginalGriff的解决方案,它使用SID。
如果你的数据超过一年,你需要在WHERE
子句中添加COMPLETED_YEAR
。
SID NAME COMPLETED_YEAR COMPLETED_MONTH COMPLETED_MONTH_NAME TOTAL_COUNT
N060698 Paul D Ottaway 2016 5 May 7
N060698 Paul D Ottaway 2016 6 June 17
N060698 Paul D Ottaway 2016 7 July 9
N060698 Paul D Ottaway 2016 8 August 22
N060698 Paul Ottaway 2016 8 August 3
N060698 Paul D Ottaway 2016 9 September 16
N060698 Paul Ottaway 2016 9 September 19
N060698 Paul D Ottaway 2016 10 October 5
N060698 Paul Ottaway 2016 10 October 7
The above is the table input.
I want to fetch records where name="Paul D Ottaway" and totalcount in August= 22+3= 25 as one record.
OUTPUT I WANT as below where i have only fetched name ="Paul D Ottaway"
SID NAME COMPLETED_YEAR COMPLETED_MONTH COMPLETED_MONTH_NAME TOTAL_COUNT
N060698 Paul D Ottaway 2016 5 May 7
N060698 Paul D Ottaway 2016 6 June 17
N060698 Paul D Ottaway 2016 7 July 9
N060698 Paul D Ottaway 2016 8 August 25
N060698 Paul D Ottaway 2016 9 September 35
N060698 Paul D Ottaway 2016 10 October 12
What I have tried:
I Tried to retrieve using count and sum.
Plese help me on this.
Try:
SELECT [Name], SUM(Total_Count) AS TotalCount FROM MyTable WHERE SID = 'N060698' GROUP BY [Name], Complete_Month
Quote:Write query to fetch name "paul D ottaway"
Did you see that your example can't use the name "paul D ottaway" to get the desired result as the second line for August is not this name?
The solution is likely to look like OriginalGriff's solution, which use SID.
If your data span on more than a year, you will need to add theCOMPLETED_YEAR
in theWHERE
clause.
这篇关于写查询以获取名称“paul D ottaway”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!