当我运行以下查询时,我得到此错误“联合类型文本和Bigint不能匹配“
问题描述:
SELECT
1 AS STEP
,'' AS ProviderName
,'' AS Procedurecode
,Claimid
,Patient_First_Name
,Patient_Last_Name
,DOS
,SUM(COALESCE(Total_Charge,0))
,SUM(COALESCE(PaidAmount,0))
,PostedDate
,CheckEFTDate
,CheckEFTNo
FROM table_name
GROUP BY ProviderName,Claimid,Patient_First_Name,Patient_Last_Name,DOS,PostedDate,CheckEFTDate,CheckEFTNo
UNION ALL
SELECT
2 AS STEP
,'' AS ProviderName
,'' AS Procedurecode
,COUNT(Claimid)
,'' AS Patient_First_Name
,'' AS Patient_Last_Name
,NULL::date AS DOS
,SUM(COALESCE(Total_Charge,0))
,SUM(COALESCE(PaidAmount,0))
,NULL::date AS PostedDate
,NULL::date AS CheckEFTDate
,'' AS CheckEFTNo
FROM table_name GROUP BY Claimid
答
如错误所示,您在UNION的两侧都有不匹配的列类型。两个查询之间的列类型必须匹配。
因此,请浏览每一列并将它们相互比较。例如:查询1中的ClaimId
与查询2中的COUNT(Claimid)
相同的类型
As the error says, you have mismatching column types on both sides of the UNION. The column types between both queries must match.
So go through each column and compare them to each other. For example: IsClaimId
in query 1 same type asCOUNT(Claimid)
in query 2