我在一家保险公司工作,必须创建一个类似这样的报告:Excel文档中的数据是如何在SSR上的
我的问题是,我不知道如何计算不同列中不同的引用、绑定和提交的#,因为它们都是从同一个字段中提取的tbl_quote.accountid
--RENEWAL BUSINESS
DECLARE @StartDate DATETIME = '05/1/18'
DECLARE @EndDate DATETIME = '11/30/2018'
DECLARE @Policy int = 33
--SUBMISSIONS
SELECT Month(S.CoverageEffDate) [Month], count(distinct Q.AccountId) as [R#ofsubmissions],(SUM(S.NotTaxableSubTotal + S.NotTaxableSubTotal2 + S.TaxableSubTotal)) as RSubmittedPremium
FROM tbl_Quote Q INNER JOIN
tbl_Quote_Scheduled_Locations S ON Q.id = S.Ouote_ID
WHERE (S.CoverageEffDate <= @EndDate) AND (S.CoverageEffDate >= @StartDate) AND (Q.Renewal = 1) AND (Q.Cancellation <> 1) and Q.Endorsement=0 and Q.Policy_ID= @policy
Group By Month(S.CoverageEffDate)
ORDER BY Month;
--QUOTES
SELECT Month(S.CoverageEffDate) [Month], count(distinct Q.AccountId) as [R#ofquotes], (SUM(S.NotTaxableSubTotal + S.NotTaxableSubTotal2 + S.TaxableSubTotal)) as RQuotedPremium
FROM tbl_Quote Q INNER JOIN
tbl_Quote_Scheduled_Locations S ON Q.id = S.Ouote_ID
WHERE (S.CoverageEffDate <= @EndDate) AND (S.CoverageEffDate >= @StartDate) AND (Q.Renewal = 1) AND (Q.Cancellation <> 1) and Q.Endorsement=0 AND (Q.QuoteStatus_OID = 6 OR Q.QuoteStatus_OID = 23 OR Q.QuoteStatus_OID = 10 OR Q.QuoteStatus_OID =8 ) and Q.Policy_ID= @policy
Group By Month(S.CoverageEffDate)
ORDER BY Month;
--BINDS
SELECT Month(S.CoverageEffDate) [Month], count(distinct Q.AccountId) as [R#ofbinds], (SUM(S.NotTaxableSubTotal + S.NotTaxableSubTotal2 + S.TaxableSubTotal)) as RBoundPremium
FROM tbl_Quote Q INNER JOIN
tbl_Quote_Scheduled_Locations S ON Q.id = S.Ouote_ID
WHERE (S.CoverageEffDate <= @EndDate) AND (S.CoverageEffDate >= @StartDate) AND (Q.Renewal = 1) AND (Q.Cancellation <> 1) and Q.Endorsement=0 AND (S.Bound = 1 or Q.QuoteStatus_OID = 23) and Q.Policy_ID= @policy
Group By Month(S.CoverageEffDate)
ORDER BY Month;
然后使用派生表。
SELECT S.[Month]
, S.[R#ofsubmissions]
, S.[RSubmittedTotalTIV]
, S.RSubmittedPremium
, Q.[R#ofquotes]
, Q.[RQuotedTotalTIV]
, Q.RQuotedPremium
, B.[R#ofbinds]
, B.[RBoundTotalTIV]
, B.RBoundPremium
FROM
(
SELECT
Month(L.CoverageEffDate) [Month],
count(distinct Q.AccountId) as [R#ofsubmissions],
SUM(L.TIV) as [RSubmittedTotalTIV],
(SUM(L.NotTaxableSubTotal + L.NotTaxableSubTotal2 + L.TaxableSubTotal)) as RSubmittedPremium
FROM tbl_Quote Q
INNER JOIN tbl_Quote_Scheduled_Locations L
ON Q.id = L.Ouote_ID
WHERE (L.CoverageEffDate <= @EndDate)
AND (L.CoverageEffDate >= @StartDate)
AND (Q.Renewal = 1) AND (Q.Cancellation <> 1)
and Q.Endorsement=0
and Q.Policy_ID= @policy
Group By Month(L.CoverageEffDate)
) S
INNER JOIN
(
SELECT
Month(L.CoverageEffDate) [Month],
count(distinct Q.AccountId) as [R#ofquotes],
SUM(L.TIV) as [RQuotedTotalTIV],
(SUM(L.NotTaxableSubTotal + L.NotTaxableSubTotal2 + L.TaxableSubTotal)) as RQuotedPremium
FROM tbl_Quote Q
INNER JOIN L
ON Q.id = L.Ouote_ID
WHERE (L.CoverageEffDate <= @EndDate)
AND (L.CoverageEffDate >= @StartDate)
AND (Q.Renewal = 1)
AND (Q.Cancellation <> 1)
and Q.Endorsement=0
AND (Q.QuoteStatus_OID = 6 OR Q.QuoteStatus_OID = 23 OR Q.QuoteStatus_OID = 10 OR Q.QuoteStatus_OID =8 )
and Q.Policy_ID= @policy
Group By Month(L.CoverageEffDate)
) Q
ON S.[Month] = Q.[Month]
INNER JOIN
(
SELECT
Month(L.CoverageEffDate) [Month],
count(distinct Q.AccountId) as [R#ofbinds],
SUM(L.TIV) as [RBoundTotalTIV],
(SUM(L.NotTaxableSubTotal + L.NotTaxableSubTotal2 + L.TaxableSubTotal)) as RBoundPremium
FROM tbl_Quote Q
INNER JOIN tbl_Quote_Scheduled_Locations L
ON Q.id = L.Ouote_ID
WHERE (L.CoverageEffDate <= @EndDate)
AND (L.CoverageEffDate >= @StartDate)
AND (Q.Renewal = 1)
AND (Q.Cancellation <> 1)
and Q.Endorsement=0
AND (L.Bound = 1 or Q.QuoteStatus_OID = 23)
and Q.Policy_ID= @policy
Group By Month(L.CoverageEffDate)
) B
ON S.[Month] = B.[Month]
ORDER BY S.[Month]
问题内容: 我如何结合这两个更新语句: 问题答案: 您可以使用CASE表达式,如下所示:
问题内容: 我正在重新编写一些PHP代码以使用PDO进行数据库访问,但是我遇到了“ WHERE … IN”查询问题。 我正在尝试根据检查表单上的哪些项目从数据库中删除某些内容。列表的长度和内容将有所不同,但是对于此示例,请想象是这样的: 然后查询如下所示: 当我这样做时,仅第一个ID被删除。(我认为它会抛出逗号及其后的所有内容。) 我也尝试过制作一个数组,但是它不会删除任何东西。 在PDO准备好的
有什么想法吗? 多谢了。
我正在尝试使用criteriaBuilder和谓词构建一个SQL where子句,以创建一些SQL语句,如: AND或对列表周围的括号对于将它们与不存在分开很重要。这是因为和有优先权我得到的是 我可以构建所有谓词,没有问题,但我不知道如何让它在AND或PAIRES列表中添加括号 AND或OR对的列表是这样构建成1个谓词列表的 子查询是这样添加的 还有地点 每个AND或AND对周围的括号也一样好
数据库:Sybase Advantage 11 在我对数据进行规范化的过程中,我试图删除从以下语句中得到的结果:
2-查询id为1的人的所有地址,2我想: 好的方法是什么?