作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的查询是
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
我的结果是
在 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/
我是一名优秀的程序员,十分优秀!