【问题标题】:Read data from two tables从两个表中读取数据
【发布时间】:2016-09-26 11:14:51
【问题描述】:

考虑下面列出的表格

Table credit

id    cr_amount  created_date
1     1000       2011-07-01
2     2000       2011-07-08
3     6000       2011-07-09

Table debit 条目如下。

id   dr_amount  created_date
1    3000       2011-07-09

需要从上面的表格中读取列cr_amountdr_amountcreated_date,如下图created date排序。

cr_amount  dr_amount   created_date
1000        NULL         2011-07-01
2000        NULL         2011-07-08
6000        NULL         2011-07-22
NULL        3000         2011-07-09

【问题讨论】:

    标签: android sqlite union-all


    【解决方案1】:

    您可能需要将两列都放在 union all 中:

    select cr_amount,Null as 'db_amount',created from table_credit
    union all
    select Null,db_amount,created from table_debit
    order by created
    

    【讨论】:

    • 不客气;如果这对您有用,请接受答案。
    猜你喜欢
    • 2023-04-04
    • 1970-01-01
    • 2013-10-21
    • 2022-01-21
    • 1970-01-01
    • 2020-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多