mysql - 如何编写查询以在我的 sql 中获取如下所示的输出

标签 mysql

账单表

Bill_date   Total
28/10/13    10000
27/10/13    5000

付款表

Paid_on    amount
28/10/13   5000
30/10/13   10000

预期输出

date        Credit    debit
27/10/13    5000    
28/10/13    10000     5000
30/10/13              10000

最佳答案

试试这个

SELECT t1.bill_date, t1.total as Credit, t2.total as debit  FROM Bills t1
LEFT JOIN Payments t2 ON t1.bill_date= t2.bill_date
UNION
SELECT t2.bill_date, t1.total as Credit, t2.total as debit FROM Bills t1
RIGHT JOIN Payments t2 ON t1.bill_date= t2.bill_date

关于mysql - 如何编写查询以在我的 sql 中获取如下所示的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19628922/

相关文章:

php - 通过 cake-php 从 db 获取不同的值

mysql - WordPress 自定义查询

php - 使用 AJAX 以 "post"登录用户的用户名到 mysql 数据库

mysql - 按字母顺序排列在最后的特殊字符 sql

复制或导入数据库时​​出现 MySQL 错误

php - 数据库 : String Json vs new column

mysql - 如何在 'from'段实现排序子查询?

mysql - 在 node.js (express) 中获取 MySQL 数据并使用 EJS 打印

mysql - 为没有任何解锁组的用户标记

php - SQL 内连接问题(可能很容易修复)