如何用多个条件连接多个表

xxhby3vn  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(370)

我有六张table
网上交易 | date | id | supplier_id | product code | 网上交易 | date | id | item | 离线交易 | date | id | 离线交易 | date | id | item | 产品 | type | product_code | 供应商 | supplier_id | country | 选择count(item),其中日期介于“2018-jun-01”和“2018-july-30”之间,并键入“Househouse”和“country=”malaysia'
这大概就是我想要达到的目标。我想联合从线上和线下的日期和id的项目,所以我会得到所有的项目组合,然后由其他要求遵循。在mysql中如何做到这一点?

izkcnapc

izkcnapc1#

SELECT count(item)
FROM online_transaction_enc
INNER JOIN online_transaction_enc ON supplier_id
INNER JOIN products ON supplier_id
...
WHERE WHERE (date BETWEEN '2010-01-30 14:15:55' AND '2010-09-29 10:15:55')
;

此解决方案使用内部联接。我相信这就是你要找的。这里有更多的文档http://www.mysqltutorial.org/mysql-inner-join.aspx

xxe27gdn

xxe27gdn2#

试试这个:

select count(a.item) from 
    (select date, id, item from online_transaction_enc
    union 
    select date, id, item from offline_transaction_enc)a
    inner join 
    (
    select  date,id,supplier_id,productcode from online_transaction
    union 
    select  date,id,supplier_id,productcode from offline_transaction)b
    on a.date=b.date and a.id=b.id
    inner join supplier on b.supplier_id=supplier.supplier_id
    inner join products on b.productcode=products.product_code
    where a.date between '20180601' And '20180730' AND Type='household' AND country='Malaysia'

相关问题