怎么写sql查询来统计?

时间:2021-11-23 08:20:05

I want to write a query for count 'noOfDistribution' within a date and by reference. for example, there are 2 in 1/5/2013.
In addition,can someone recommend some ebook/website to learn advanced skills in query? Thanks for helping.

我想在日期和引用中为count'noOfDistribution'写一个查询。例如,2013年1月5日有2个。另外,有人可以推荐一些电子书/网站来学习查询的高级技巧吗?谢谢你的帮助。

怎么写sql查询来统计?

2 个解决方案

#1


Answering your question:

回答你的问题:

SELECT input_Date, REFERENCE, count(*)
FROM YourTable
GROUP BY input_Date, REFERENCE

But it will result something different you pointed, since for the date 2/5/2013, it will count 6 elements for REFERENCE null

但是它会导致你指出的不同之处,因为对于2013年2月5日,它会为REFERENCE null计算6个元素

#2


You can do something like thiss....

你可以做这样的事....

select count(Input_date) over (partition by Input_date,reference),*    from table

By this you can find count of Particular date such as 1/5/2013 has 2 count

通过这个您可以找到特定日期的计数,如1/5/2013有2个计数

alternative way

select date,reference,count(*) from table group by date,reference

#1


Answering your question:

回答你的问题:

SELECT input_Date, REFERENCE, count(*)
FROM YourTable
GROUP BY input_Date, REFERENCE

But it will result something different you pointed, since for the date 2/5/2013, it will count 6 elements for REFERENCE null

但是它会导致你指出的不同之处,因为对于2013年2月5日,它会为REFERENCE null计算6个元素

#2


You can do something like thiss....

你可以做这样的事....

select count(Input_date) over (partition by Input_date,reference),*    from table

By this you can find count of Particular date such as 1/5/2013 has 2 count

通过这个您可以找到特定日期的计数,如1/5/2013有2个计数

alternative way

select date,reference,count(*) from table group by date,reference