Code: Select all
$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();
< /code>
Siehe, wo Klausel: < /p>
WHERE note1.noteType = 'cash_in'
Meine Tabelle hat auch Bargelddaten. Anmerkung | Notetitle | Notedate | oneAmount | categoryId | Notetyp |
Kategorie Tabelle:
| categoryId | CategoryName | ParentID |