我想根据相关表格的值,单独显示重新提交和第一次提交(两者都是声明类型)。
所以我使用下面的查询单独获取两个记录。
SELECT ROUND(coalesce(SUM(c.ClaimNet), 0), 2) as net,
MAX(c.ClaimID), count(c.ClaimID) as claims,
MAX(h.TransactionDate) as TransactionDate,
'Resubmission' AS 'Claim Type'
FROM Claim c
LEFT OUTER JOIN ClaimHeader h on h.HeaderID = c.HeaderPKID
INNER JOIN Resubmission r ON r.ClaimID = c.ClaimPKID WHERE h.HeaderType=2
UNION ALL
SELECT ROUND(coalesce(SUM(c.ClaimNet), 0), 2) as net,
MAX(c.ClaimID), count(c.ClaimID) as claims,
MAX(h.TransactionDate) as TransactionDate,
'First Submission' AS 'Claim Type'
FROM Claim c
LEFT OUTER JOIN ClaimHeader h on h.HeaderID = c.HeaderPKID
WHERE ClaimPKID NOT IN
( SELECT ClaimID FROM Resubmission GROUP BY ClaimID ) AND HeaderType=2
在上面的查询中,我使用UNION ALL
从声明表中获取数据。如果声明表主键在重新提交表中用作外键,那么它是重新提交声明类型,如果它未在重新提交表中使用,那么它是第一次提交。< / p>
我的问题是尽管表格中没有特定选择查询的记录,但它通过提及索赔类型返回Null值。请参考下面的截图。
答案 0 :(得分:1)
试试这个:
main
答案 1 :(得分:1)
没有分组的聚合总是返回一行,即使没有数据也是如此。为避免这种情况,您只需添加<img class="tio-enable" src="image.png" name="test" id="test-tioButton">
:
HAVING COUNT(*) > 0