我编写了一个 SQL 查询,它根据以下条件从单个表 (date,account,dr,cr
) 中提取数据:
select * from (select date,account,dr from sys_credit_debit where dr != 0) as t1,
(select date,account,cr from sys_credit_debit where cr != 0) as t2
我想在表格左侧显示借方数据,在右侧显示贷方数据。知道行可以不同这一事实。但是,我通过查询获取了双倍数据。
有人可以帮我吗?
最佳答案
尝试以下查询
SELECT t1.*,t2.* FROM
(select date,account,dr from sys_credit_debit where dr != 0) as t1
INNER JOIN
(select date,account,cr from sys_credit_debit where cr != 0) as t2
ON t1.account = t2.account AND t1.date = t2.date
关于php - 合并 2 个具有不同行数的子查询。获得双倍数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40230753/