gpt4 book ai didi

mysql - My SQL 查询中的空值

转载 作者:行者123 更新时间:2023-11-29 11:22:17 25 4
gpt4 key购买 nike

我的查询是

SELECT i.status,i.amount_total, i.id,sc.category as category,us.fname as name,us.company as company,
(SELECT transaction_id FROM invoice_payments WHERE invoice_payments.invoice_id = i.id) as transaction_id ,
(SELECT created FROM invoice_payments WHERE invoice_payments.invoice_id = i.id and invoice_payments.created BETWEEN '2015-01-01' and '2016-01-01') as created
FROM invoices i
inner JOIN
users as us ON us.id = i.client_id
inner JOIN subscriptioncategory as sc ON sc.user_id = us.id

我的结果是

enter image description here

在 Created 列中,我不应该得到空值。是否有任何简单的查询可以修复它。

最佳答案

只需使用内连接连接所有表:

SELECT i.status,i.amount_total, i.id,sc.category as category,us.fname as name,us.company as company,
ip.transaction_id,
ip1.created
FROM invoices i
inner JOIN
users as us ON us.id = i.client_id
inner JOIN subscriptioncategory as sc ON sc.user_id = us.id
join invoice_payments ip on ip.invoice_id = i.id
join invoice_payments ip1 WHERE ip1.invoice_id = i.id and ip1.created BETWEEN '2015-01-01' and '2016-01-01'

关于mysql - My SQL 查询中的空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38717919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com