如何解决Mysql UNION-在同一行中获取结果
SELECT COUNT(status) AS COUNT
FROM financeinstallment
WHERE status = 1
GROUP BY financeId
UNION
SELECT finance.financeId,finance.customerId,customer.customerName,customer.phone1,customer.aadhaar,finance.financeStartDate,finance.vehicleNumber,finance.loanAmount,finance.totalInstallment,finance.InstallmentAmount
FROM finance
INNER JOIN customer ON customer.customerId = finance.customerId
如何在同一行中获取结果?
我遇到以下错误:
错误代码:1222。使用的SELECT语句具有不同的列数0.000秒
解决方法
这里的一种方法可能是将联合中的第二个查询作为子查询连接到第一个查询。
SELECT
t.count,f.financeId,f.customerId,c.customerName,c.phone1,c.aadhaar,f.financeStartDate,f.vehicleNumber,f.loanAmount,f.totalInstallment,f.InstallmentAmount
FROM finance f
INNER JOIN customer c
ON c.customerId = f.customerId
INNER JOIN
(
SELECT financeId,COUNT(status) AS count
FROM financeinstallment
WHERE status = 1
GROUP BY financeId
) t
ON f.financeId = t.financeId;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。