在sql Oracle中查找总点击量和访问者

在sql Oracle中查找总点击量和访问者,sql,oracle,Sql,Oracle,我有一个表appWebStats,其中包含以下表字段appName、userName、dateTime 我试过了 select Count(a.appName) as totalHits , Count(a.distinct userName) as visitors , a.dateTime from appWebStats a where date between time between '11-APR-12' and '14-APR-12' grou

我有一个表appWebStats,其中包含以下表字段appName、userName、dateTime

我试过了

select Count(a.appName) as totalHits ,
       Count(a.distinct userName) as visitors ,
       a.dateTime 
from appWebStats a 
where date between time between '11-APR-12' and '14-APR-12'   
group by a.appName ,a.userName,a.dateTime;
但它在所有行中都返回1

这里可能出了什么问题

编辑:

我想要的是

day      appname     totalHist uniqueVisitors
11         app1          56         5
11         app2          36         8
11         app3          26         7
12         app1          56         6
12         app2          36         8
13         app1          27         9
14         app2          34         4

你的查询没有按照你的问题所说的做。如果您希望按应用程序访问,请按应用程序分组并统计访问者:

select a.appName, 
       count(*) as visitors, 
       count(distinct a.userName) as uniqueVisitors
from table a
where datetime between '11-APR-12' and '14-APR-12'
group by a.appName;
相反,如果你想知道每天应用程序和访问者的数量,那么就利用时间

select trunc(a.datetime) as theday, 
       count(distinct a.appName) as numapps,
       count(distinct a.userName) as uniqueVisitors
from table a
where datetime between '11-APR-12' and '14-APR-12'
group by trunc(a.datetime)
order by 1;
编辑:

我想你要问的问题是:

select trunc(a.datetime) as theday, a.appName as numapps,
       count(*) as TotalHist,
       count(distinct a.userName) as uniqueVisitors
from table a
where datetime between '11-APR-12' and '14-APR-12'
group by trunc(a.datetime), a.appName
order by trunc(a.datetime), a.appName;

你的查询没有按照你的问题所说的做。如果您希望按应用程序访问,请按应用程序分组并统计访问者:

select a.appName, 
       count(*) as visitors, 
       count(distinct a.userName) as uniqueVisitors
from table a
where datetime between '11-APR-12' and '14-APR-12'
group by a.appName;
相反,如果你想知道每天应用程序和访问者的数量,那么就利用时间

select trunc(a.datetime) as theday, 
       count(distinct a.appName) as numapps,
       count(distinct a.userName) as uniqueVisitors
from table a
where datetime between '11-APR-12' and '14-APR-12'
group by trunc(a.datetime)
order by 1;
编辑:

我想你要问的问题是:

select trunc(a.datetime) as theday, a.appName as numapps,
       count(*) as TotalHist,
       count(distinct a.userName) as uniqueVisitors
from table a
where datetime between '11-APR-12' and '14-APR-12'
group by trunc(a.datetime), a.appName
order by trunc(a.datetime), a.appName;

你的查询没有按照你的问题所说的做。如果您希望按应用程序访问,请按应用程序分组并统计访问者:

select a.appName, 
       count(*) as visitors, 
       count(distinct a.userName) as uniqueVisitors
from table a
where datetime between '11-APR-12' and '14-APR-12'
group by a.appName;
相反,如果你想知道每天应用程序和访问者的数量,那么就利用时间

select trunc(a.datetime) as theday, 
       count(distinct a.appName) as numapps,
       count(distinct a.userName) as uniqueVisitors
from table a
where datetime between '11-APR-12' and '14-APR-12'
group by trunc(a.datetime)
order by 1;
编辑:

我想你要问的问题是:

select trunc(a.datetime) as theday, a.appName as numapps,
       count(*) as TotalHist,
       count(distinct a.userName) as uniqueVisitors
from table a
where datetime between '11-APR-12' and '14-APR-12'
group by trunc(a.datetime), a.appName
order by trunc(a.datetime), a.appName;

你的查询没有按照你的问题所说的做。如果您希望按应用程序访问,请按应用程序分组并统计访问者:

select a.appName, 
       count(*) as visitors, 
       count(distinct a.userName) as uniqueVisitors
from table a
where datetime between '11-APR-12' and '14-APR-12'
group by a.appName;
相反,如果你想知道每天应用程序和访问者的数量,那么就利用时间

select trunc(a.datetime) as theday, 
       count(distinct a.appName) as numapps,
       count(distinct a.userName) as uniqueVisitors
from table a
where datetime between '11-APR-12' and '14-APR-12'
group by trunc(a.datetime)
order by 1;
编辑:

我想你要问的问题是:

select trunc(a.datetime) as theday, a.appName as numapps,
       count(*) as TotalHist,
       count(distinct a.userName) as uniqueVisitors
from table a
where datetime between '11-APR-12' and '14-APR-12'
group by trunc(a.datetime), a.appName
order by trunc(a.datetime), a.appName;

@海德。您应该使用不同的查询来查看聚合的作用。如果您打算使用SQL,您应该了解该语言是如何工作的。@Haider。您应该使用不同的查询来查看聚合的作用。如果您打算使用SQL,您应该了解该语言是如何工作的。@Haider。您应该使用不同的查询来查看聚合的作用。如果您打算使用SQL,您应该了解该语言是如何工作的。@Haider。您应该使用不同的查询来查看聚合的作用。如果您打算使用SQL,您应该了解该语言是如何工作的。