【发布时间】:2019-03-14 10:21:32
【问题描述】:
我有这样的 MySQL 查询:(我使用 CodeIgniter)
$report = $this->db->query("
SELECT c.categoryName,
note1.*,
((SELECT SUM(noteAmount)
FROM notes
WHERE DATE_FORMAT(noteDate, '%d-%m-%Y') = DATE_FORMAT(note1.noteDate, '%d-%m-%Y') AND noteType = 'cash_in')
-
(SELECT SUM(noteAmount)
FROM notes
WHERE DATE_FORMAT(noteDate, '%d-%m-%Y') = DATE_FORMAT(note1.noteDate, '%d-%m-%Y') AND noteType = 'cash_out')) as trxCount
FROM notes AS note1
JOIN
(SELECT noteDate
FROM notes
GROUP BY noteDate
HAVING COUNT(noteDate) > 0)
AS note2
ON note1.noteDate = note2.noteDate
JOIN category c
ON c.categoryID = note1.categoryID
WHERE note1.noteType = 'cash_in'
ORDER BY note1.noteDate DESC
LIMIT $start, $per_page
")->result();
查看 WHERE 子句:WHERE note1.noteType = 'cash_in'
我只想拿现金数据,但为什么我得到所有数据? (包括提现等)。我的表也有提现数据
备注表:
noteID |注意标题 |注意日期 |注意金额 |类别ID |笔记类型
分类表
类别ID |类别名称 |父ID
【问题讨论】:
-
您遇到什么错误?还请发布注释和类别表中的一些示例数据以及预期的输出。
-
没有错误。但查询返回所有数据(兑现和兑现)。我只想拿现金
-
将示例数据添加到您的表中
标签: php mysql sql codeigniter