1

我正在开发使用 PL/SQL 数据库的开放文本内容服务器工具。我要做的是通过 6 个不同的查询获取计数数据,这些查询也有不同的条件和不同的表。我试图结合所有这 6 个计数查询,但没有运气。以下是列出的这 6 个查询:

一个月内创建的文件:

select count (dataid) from Dtree where 
Createdate >= %1 and createdate <= %2 and subtype = 144

用户总数:

select count(a.id) from Kuaf a, kuaf b where 
a.deleted =0 and a.type =0 and b.id = a.groupid

每月登录的唯一用户数(计数):

Select count (distinct (performerID))
from dauditnew where auditid=23 and auditdate >= %1 and auditdate <= %2

一个月内创建的用户(计数):

Select Count(dataid) FROM DAUDITNEW where AUDITID = 1 
AND AUDITSTR LIKE 'Create' and subtype=142 AND 
auditdate >= %1 and auditdate <= %2

删除的用户(计数):

SELECT count(a.userid) from dauditnew a WHERE
a.auditstr = 'Delete' AND 
a.AuditDate >= %1 AND 
a.AuditDate <= %2 AND 
a.UserID in (Select ID from KUAF where Deleted = 1 and Type=0)

启动的工作流程:

Select count(*) from Wworkaudit WWA where WWA.workaudit_status=1 AND 
WWA.workaudit_date >= %1 and WWA.workaudit_date <= %2

这里 %1,%2 表示用户输入。由于这 6 个查询都有非常不同的条件,因此将它们组合起来对我来说似乎是一项艰巨的任务。请帮帮我。

谢谢你。

4

2 回答 2

3
SELECT (
         select count (dataid)
         from   Dtree
         where  Createdate BETWEEN :start_date and :end_date
         and    subtype = 144
       ) AS Docs_Per_Month,
       (
         select count(a.id)
         from   Kuaf a INNER JOIN kuaf b ON (b.id = a.groupid)
         where  a.deleted = 0
         and    a.type    = 0
       ) AS Total_No_of_Users,
       (
         Select count( distinct performerID )
         from   dauditnew
         where  auditid = 23
         and    auditdate BETWEEN :start_date and :end_date
       ) AS Unique_Users_in_Month,
       (
         Select Count(dataid)
         FROM   DAUDITNEW
         where  AUDITID  = 1 
         AND    AUDITSTR = 'Create'
         and    subtype  = 142
         AND    auditdate BETWEEN :start_date and :end_date
       ) AS Users_Created_in_Month,
       (
         SELECT count(a.userid)
         from   dauditnew a
         WHERE  a.auditstr = 'Delete'
         AND    a.auditdate BETWEEN :start_date and :end_date
         AND    a.UserID in (Select ID from KUAF where Deleted = 1 and Type=0)
       ) AS Users_Deleted,
       (
         Select count(*)
         from   Wworkaudit
         where  workaudit_status = 1
         AND    workaudit_date BETWEEN :start_date and :end_date
       ) AS Workflows_Initiated
FROM   DUAL;
于 2016-06-24T18:39:57.320 回答
0

使用 UNION ALL 语句

前任。select count (ax) from a...where... UNION ALL select count (bz) from b...where... UNION ALL select count (cy) from c...where... etc.

注意:必须使用 UNION ALL,因为如果使用常规 UNION,将不会显示重复的结果

于 2016-06-24T18:20:31.827 回答