只想通过unitid

时间:2016-02-26 17:45:20

标签: oracle reporting-services ssrs-2008-r2 bids

我正在使用SSRS查询oracle数据库。

所以我有一个数据源,这个报告应该在一个唯一的unitid上找到基于多个开放工作单的重复工作订单。因此,我只想显示具有多个条目的组,因为它们按unitid分组。

 SELECT
 COMPSTSB.UNITID,
 COMPSTSB.UNITTYPE,
 ACTDEFN.ACTDESC,
 ACTDEFN.ACTCODE,
 HISTORY.WONO, 
 HISTORY.COMPFLAG,
 HISTORY.ADDDTTM,
 HISTORY.COMMENTS
 FROM   (IMSV7.COMPSTSB COMPSTSB INNER JOIN IMSV7.HISTORY HISTORY ON
 COMPSTSB.COMPKEY=HISTORY.COMPKEY) INNER JOIN IMSV7.ACTDEFN ACTDEFN ON 
 HISTORY.ACTKEY=ACTDEFN.ACTKEY
 WHERE  HISTORY.COMPFLAG='Y' AND  NOT (ACTDEFN.ACTCODE='DBR' OR     ACTDEFN.ACTCODE='IN')
 ORDER BY COMPSTSB.UNITTYPE, COMPSTSB.UNITID, HISTORY.ADDDTTM

有人能指出我正确的方向吗?是的,在有人说这已被问过一百万次之前,我确实进行了搜索。把我指向百万次,我会看到我是否认为他们符合我的问题。理想情况下,在SQL中,我可以创建返回unitid计数的新列,但我确实尝试了但失败了,然后我可以过滤该列以删除任何只有一个计数的列。我真的不认为这应该是困难的,但到目前为止我花了大约4个小时。

提前致谢! 史蒂芬

2 个答案:

答案 0 :(得分:0)

我希望您关注UNITID表中IMSV7.COMPSTSB的重复值。如果是这样,将此联接添加到您的查询中应该允许您识别它们:

 JOIN (SELECT COMPSTSB.UNITID
         FROM IMSV7.COMPSTSB
        GROUP BY COMPSTSB.UNITID
       HAVING COUNT(COMPSTSB.UNITID) > 1) dups
   ON DUPS.UNITID = COMPSTSB.UNITID
 JOIN IMSV7.HISTORY HISTORY

以下是完整查询:

 SELECT COMPSTSB.UNITID
      , COMPSTSB.UNITTYPE
      , ACTDEFN.ACTDESC
      , ACTDEFN.ACTCODE
      , HISTORY.WONO
      , HISTORY.COMPFLAG
      , HISTORY.ADDDTTM
      , HISTORY.COMMENTS
   FROM IMSV7.COMPSTSB COMPSTSB
   JOIN (SELECT COMPSTSB.UNITID
           FROM IMSV7.COMPSTSB
          GROUP BY COMPSTSB.UNITID
         HAVING COUNT(COMPSTSB.UNITID) > 1) dups
     ON DUPS.UNITID = COMPSTSB.UNITID
   JOIN IMSV7.HISTORY HISTORY
     ON COMPSTSB.COMPKEY = HISTORY.COMPKEY
   JOIN IMSV7.ACTDEFN ACTDEFN
     ON HISTORY.ACTKEY = ACTDEFN.ACTKEY
  WHERE HISTORY.COMPFLAG = 'Y'
    AND ACTDEFN.ACTCODE NOT IN ('DBR','IN')
  ORDER BY COMPSTSB.UNITTYPE
      , COMPSTSB.UNITID
      , HISTORY.ADDDTTM;

由于上述查询不起作用,您可以尝试在每个表上对类似的子查询进行外连接,并仅限制外连接表返回数据的记录。这将显示查询中的哪些表正在为您的额外行设置。:

 SELECT COMPSTSB.UNITID
      , COMPSTSB.UNITTYPE
      , ACTDEFN.ACTDESC
      , ACTDEFN.ACTCODE
      , HISTORY.WONO
      , HISTORY.COMPFLAG
      , HISTORY.ADDDTTM
      , HISTORY.COMMENTS
      , DUPS.UNITID UNITID_DUP
      , DUPS2.COMPKEY COMPKEY_DUP
      , DUPS3.ACTKEY ACTKEY_DUP
   FROM IMSV7.COMPSTSB COMPSTSB
   JOIN IMSV7.HISTORY HISTORY
     ON COMPSTSB.COMPKEY = HISTORY.COMPKEY
   JOIN IMSV7.ACTDEFN ACTDEFN
     ON HISTORY.ACTKEY = ACTDEFN.ACTKEY
   LEFT JOIN (SELECT COMPSTSB.UNITID
           FROM IMSV7.COMPSTSB
          GROUP BY COMPSTSB.UNITID
         HAVING COUNT(COMPSTSB.UNITID) > 1) dups
     ON DUPS.UNITID = COMPSTSB.UNITID
   LEFT JOIN (SELECT HISTORY.COMPKEY
           FROM IMSV7.HISTORY
          GROUP BY HISTORY.COMPKEY
         HAVING COUNT(HISTORY.COMPKEY) > 1) dups2
     ON DUPS.UNITID = COMPSTSB.UNITID
   LEFT JOIN (SELECT ACTDEFN.ACTKEY
           FROM IMSV7.ACTDEFN
          GROUP BY ACTDEFN.ACTKEY
         HAVING COUNT(ACTDEFN.ACTKEY) > 1) dups3
     ON DUPS.UNITID = COMPSTSB.UNITID
  WHERE HISTORY.COMPFLAG = 'Y'
    AND ACTDEFN.ACTCODE NOT IN ('DBR','IN')
    AND ( DUPS.UNITID   IS NOT NULL OR
          DUPS2.COMPKEY IS NOT NULL OR
          DUPS3.ACTKEY  IS NOT NULL)
  ORDER BY COMPSTSB.UNITTYPE
      , COMPSTSB.UNITID
      , HISTORY.ADDDTTM;

答案 1 :(得分:0)

如果我理解您的问题,以下内容应该为您提供所需的信息:

SET NOCOUNT ON
CREATE TABLE #TempTable (
PhysicalMemoryGB Decimal (20, 2),
BufferPoolCommittedMemoryGB Decimal (20, 2),  
BufferPoolTargetMemoryGB Decimal (20, 2),
MinServerMemoryGB Decimal (20, 2),
MaxServerMemoryGB Decimal (20, 2),
TotalServerMemoryMB Decimal (20, 2)
)
GO

INSERT INTO #TempTable (PhysicalMemoryGB, BufferPoolCommittedMemoryGB,          BufferPoolTargetMemoryGB, MinServerMemoryGB, MaxServerMemoryGB,   TotalServerMemoryMB)


SELECT CAST(physical_memory_in_bytes / (1024.0 * 1024.0 * 1024.0) AS DECIMAL (20, 2)) AS PhysicalMemoryGB,
CAST ((bpool_committed * 8) / (1024.0 * 1024.0) AS DECIMAL (20, 2)) AS BufferPoolCommittedMemoryGB,
CAST ((bpool_commit_target * 8) / (1024.0 * 1024.0) AS DECIMAL (20, 2) AS BufferPoolTargetMemoryGB,

(
SELECT CAST(CAST(value_in_use AS INT) / 1024.0 AS DECIMAL(20, 2))
FROM sys.configurations
WHERE name = 'min server memory (MB)'
) AS MinServerMemoryGB,

(
SELECT CAST(CAST(value_in_use AS INT) / 1024.0 AS DECIMAL(20, 2))
FROM sys.configurations
WHERE name = 'max server memory (MB)'
) AS MaxServerMemoryGB,



(
SELECT cntr_value / 1024.0
FROM sys.dm_os_performance_counters
WHERE counter_name = 'Total Server Memory(KB)'
) AS TotalServerMemoryMB
FROM sys.dm_os_sys_info WITH(NOLOCK);

DECLARE @PhysicalMemoryGB DECIMAL(20, 2),
@BufferPoolCommittedMemoryGB DECIMAL(20, 2),
@BufferPoolTargetMemoryGB DECIMAL(20, 2),
@MinServerMemoryGB DECIMAL (20, 2),
@MaxServerMemoryGB DECIMAL (20, 2),
@TotalServerMemoryMB DECIMAL (20, 2)

BEGIN

IF @BufferPoolCommittedMemoryGB > 14.99
THEN 
DBCC FreeProcCache
DBCC FreeSystemCache
DBCC FreeSessionCache

END 

DROP Table #TempTable

END