English 中文(简体)
全面外包商Join未返回未配对的外地价值
原标题:Full Outer Join not returning unmatched join field values SQL SERVER 2005

我使用以下代码计算一个月的保险费,这个月是9月。 现行法典规定,在9月30日之前将全部所得保险费减去截至8月31日的全部收入溢价,以便单单单在9月份回扣保险费。

成果就是这样:

eprem        coveragecode  
0.0211       AD  
277970.8291  BI  
245700.6741  COLL  
86997.5694   COMP  
85.0083      CustomParts  
848.7873     Death  
0.00         ECL  
0.00         GPIP  
692.3802     Income  
2410.5513    MED  
267670.1099  PD  
387628.504   PIP  
26.8767      PU  
11736.2762   Rental  
4304.3367    Towing   
4211.2574    UIMBI  
19804.8964   UMBI  
15145.3211   UMPD  

当我增加所有保险的溢价,即第13253399号保费,这是平时月的准确保费。

现在,我试图做的是,也因此而增加编码。 如果在《法典》中没有任何具体规定的编码编码栏下运行以下代码,那么我得出上述结果是正确的,但是,如果加上“计算代码”一栏,即退回到预期的数千个牢房,但如果加上总保值,即达到132 3608.401美元,而不是正确的总数为13253 999美元。 我认为,正在发生的情况是,在1个月(上表)和另一个月(上表)存在某些保险和保险套组合(即与我的2个衍生表格合并)。 当我有权利加入时,我会收到不同数额的退款,但是,如果加上所有保费,则总是等于132 3608.401美元,而不是13233.399美元。 我认为,解决我的问题的办法是,全面加入,从而恢复所有成果(甚至那些不匹配的结果),这样,我的总保费将增加到第13233.399号,但不管加入哪一类尝试使用,我还是只得到第1323608.401号。 是否有任何想法可以在此讨论? 任何援助都将受到高度赞赏。 感谢!

    SELECT   sept.eprem-aug.eprem as eprem , sept.coveragecode, zipcode 
from

(select 
SUM(EarnedPremium) AS eprem,coveragecode, evaluationdate, zipcode                       
FROM         dbo.StatRateSummary                            
where evaluationdate =  09-30-2011  
and decpagetypecode !=  x 
GROUP BY evaluationdate ,coveragecode, zipcode

) as sept full outer join 

(select 
SUM(EarnedPremium) AS eprem,coveragecode, evaluationdate, zipcode                       
FROM         dbo.StatRateSummary                            
where evaluationdate = CONVERT(DATETIME, DATEADD(d,-1,DATEADD(mm, DATEDIFF(m,0, 09-30-2011 ),0)), 102)  
and decpagetypecode !=  x 
GROUP BY evaluationdate ,coveragecode, zipcode

) as aug on sept.coveragecode = aug.coveragecode and sept.zipcode = aug.zipcode
where sept.coveragecode is not null and sept.coveragecode <>   
order by coveragecode, sept.evaluationdate
最佳回答

我必须做的是,把任何无价溢价转换为0。

SELECT   isnull(sept.eprem,0)-isnull(aug.eprem,0) as eprem , sept.coveragecode, zipcode 
from

(select 
SUM(EarnedPremium) AS eprem,coveragecode, evaluationdate, zipcode                       
FROM         dbo.StatRateSummary                            
where evaluationdate =  09-30-2011  
and decpagetypecode !=  x 
GROUP BY evaluationdate ,coveragecode, zipcode

) as sept full outer join 

(select 
SUM(EarnedPremium) AS eprem,coveragecode, evaluationdate, zipcode                       
FROM         dbo.StatRateSummary                            
where evaluationdate = CONVERT(DATETIME, DATEADD(d,-1,DATEADD(mm, DATEDIFF(m,0, 09-30-2011 ),0)), 102)  
and decpagetypecode !=  x 
GROUP BY evaluationdate ,coveragecode, zipcode

) as aug on sept.coveragecode = aug.coveragecode and sept.zipcode = aug.zipcode
where sept.coveragecode is not null and sept.coveragecode <>   
order by coveragecode, sept.evaluationdate
问题回答

阁下的“未来”状况应如此:

SELECT   sept.eprem-aug.eprem as eprem , sept.coveragecode, zipcode 
from

(select 
SUM(EarnedPremium) AS eprem,coveragecode, evaluationdate, zipcode                       
FROM         dbo.StatRateSummary                            
where evaluationdate =  09-30-2011  
and decpagetypecode !=  x 
-- Migrated WHERE Condition
AND COALESCE(eprem.coveragecode,   ) >   
GROUP BY evaluationdate ,coveragecode, zipcode

) as sept FULL OUTER join 

(select 
SUM(EarnedPremium) AS eprem,coveragecode, evaluationdate, zipcode                       
FROM         dbo.StatRateSummary                            
where evaluationdate = CONVERT(DATETIME, DATEADD(d,-1,DATEADD(mm, DATEDIFF(m,0, 09-30-2011 ),0)), 102)  
and decpagetypecode !=  x 
GROUP BY evaluationdate ,coveragecode, zipcode

) as aug on sept.coveragecode = aug.coveragecode and sept.zipcode = aug.zipcode
/*
|| See SEPT derived table for elimination of NULL and    coverage codes
|| where sept.coveragecode is not null and sept.coveragecode <>   
*/
order by coveragecode, sept.evaluationdate

考虑的一个问题是,当你使用<代码>时。 OUTER JOIN. WHERE criteria , 从而使最佳机构得以重新作为INNER JOIN

希望这一帮助。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

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 ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签