English 中文(简体)
根据标准编制一个表格和比较
原标题:Splitting one table based on criteria and comparing
  • 时间:2012-01-12 16:13:55
  •  标签:
  • sql
  • oracle

我不敢肯定这一具体询问的最好方式,因此我希望标题是充分的,但我将试图描述我需要怎样理解。 简言之,这是为了 or。

我们有一个称为评估的表格。 然而,本表内有不同类型的评估,有些评估应按照逻辑顺序和在规定时限内进行。 当客户对同一类型进行多种评估时,问题就会出现,因为我们必须在外部使用一种相当低的阵列公式,以确定哪些全面评估与初步评估相吻合。

我早就在这个网站上解决了一个问题(https://stackoverflow.com/questions/8615286/returning-related-date-from-multiple-table-info-or>从多个表格中重新排列相关日期,包括载于fo的附加表格),我认为这些表格含有许多必要的逻辑(特别是确定在规定时限内发生的相应事件)。 然而,虽然询问将数据从3个适当表格(评估、事件、反应)中删除,但我现在需要提出一个问题,产生类似的结果,但从1个主要表格和2个表格中抽取,来回工人的信息。 我认为,最合乎逻辑的方法是建立一个以一种评估形式审视评估表的询问,然后再次加入评估表(可能是一个临时表格)并采用最初的评估类型。

例如:

表1

Client    ID    Assessment Type   Start       End
P1        1     Initial           01/01/2012  05/01/2012

表2 (评估节奏):

Client ID    Assessment Type   Start       End
P1     2     Full              12/01/2012 

表3

ID     Worker     Team
1      Bob        Team1
2      Lyn        Team2

结果:

Client  ID    Initial Start    Initial End    Initial Worker   Full Start   Full End   
P1      1     01/01/2012       05/01/2012     Bob              12/01/2012

因此,表1和表2取自同一表格,但重复了不同的评估。 理想的情况是,进行核查,以确保全面评估在初步评估结束后X天内开始(类似于前面提到的前一次查询中可能进行的核查)。 如果能够做到这一点,也许值得一提的是,我也有兴趣扩大这一范围,以研究多种评估类型,因为在周期中,预期客户在4至5种不同类型的评估之间会有大致相同的评估。 任何人都值得赞赏,我早就已经得到了这个非常宝贵的社区的大量帮助。

Edit:

根据甲基溴咨询纳入解决办法。

Select
*
From(
Select
I.ASM_SUBJECT_ID as PNo,
I.ASM_ID As IAID,
I.ASM_QSA_ID as IAType,
I.ASM_START_DATE as IAStart,
I.ASM_END_DATE as IAEnd,
nvl(olm_bo.get_ref_desc(I.ASM_OUTCOME, ASM_OUTCOME ),  ) as IAOutcome,
C.ASM_ID as CAID,
C.ASM_QSA_ID as CAType,
C.ASM_START_DATE as CAStart,
C.ASM_END_DATE as CAEnd,
nvl(olm_bo.get_ref_desc(C.ASM_OUTCOME, ASM_OUTCOME ),  ) as CAOutcome,
ROUND(C.ASM_START_DATE -I.ASM_START_DATE,0) as "Likely",
row_number() over(PARTITION BY  I.ASM_ID                   
ORDER BY 
abs(I.ASM_START_DATE -  C.ASM_START_DATE))as "Row Number"
FROM
O_ASSESSMENTS I
left join O_ASSESSMENTS C
on I.ASM_SUBJECT_ID = C.ASM_SUBJECT_ID
and C.ASM_QSA_ID  IN ( AA523 , AA1326 ) and
ROUND(C.ASM_START_DATE - I.ASM_START_DATE,0) >= -2
AND
ROUND(C.ASM_START_DATE -  I.ASM_START_DATE,0) <= 25
and C.ASM_OUTCOME <> ABANDON 
Where I.ASM_QSA_ID  IN ( AA501 , AA1323 )
AND I.ASM_OUTCOME <>  ABANDON 
AND
I.ASM_END_DATE >=  01-04-2011 ) WHERE "Row Number" = 1 
最佳回答

仅凭表别,你可以多次在KQQ中查询同一表格。 因此,这样做的一个途径是:

select i.client,
       i.id     initial_id,
       i.start  initial_start,
       i.end    initial_end,
       w.worker initial_worker,
       f.id     full_id,
       f.start  full_start,
       f.end    full_end
from assessments i
join workers w on i.id = w.id
left join assessments f 
       on i.client = f.client and 
          f.assessment_type =  Full  and
          f.start between i.end and i.end + X 
/* replace X with appropriate number of days */
where i.assessment_type =  Initial 

注:栏目名称,如<代码>end 通常应双重引用(即Oraclekou语中的保留词),但从前一个问题来看,它所看到的是,这些词语是实际列名的简化版本。

问题回答

From your post, I assume that you re using Oracle here (as I see "Oracle" in the question).

关于“典型”表格,意见是正确的。 一项Oracle观点可以给你一个像你重新寻找不同类型的评估一样可靠的表格。

Don Burleson是任何与甲骨质有关的事情的良好来源,他在 rel=“nofollow”>http://www.dba-oracle.com/concepts/views.htm上对Oracle的见解做了一些改动。





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

How to make a one to one left outer join?

I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, ...

Insert if not exists Oracle

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL ...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

热门标签