gpt4 book ai didi

sql - 无法匹配 UNION 类型 "..."和 "..."

转载 作者:行者123 更新时间:2023-11-29 11:21:48 24 4
gpt4 key购买 nike

当我运行以下查询时,出现此错误

UNION types text and bigint cannot be matched

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

最佳答案

我的错误是在联合中列名不重要,但顺序很重要(也许我错了,我找不到文档)

例子:

1)这很好

select
1 :: integer as someint,
'1' :: text as sometext

union

select
2 :: integer as someint,
'2' :: text as sometext

返回

someint sometext
1 1 1
2 2 2

2)这不行

select
1 :: integer as someint,
'1' :: text as sometext

union

select
'2' :: text as sometext,
2 :: integer as someint

抛出

Error(s), warning(s):

42804: UNION types integer and text cannot be matched

自己试试 https://rextester.com/l/postgresql_online_compiler

关于sql - 无法匹配 UNION 类型 "..."和 "...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31520629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com