我从isRead = 0的表通知中获取Title和COUNT(isRead)
它正在获取标题,并且每个标题的读取计数。很好,然后返回
Title count
john 3
denil 4
@Query("SELECT title,COUNT(isRead)as isRead FROM Notification WHERE
pkgName = :packagename and isRead=0 Group By title")
但如果count = 0,则返回null。
我需要的是以下内容;
Title count
john 0
denil 0
我该怎么办。?
答案 0 :(得分:1)
如果您希望包的表中包含所有数据,则将条件移至SELECT
SELECT title, COUNT(CASE WHEN isRead = 0 THEN 1 ELSE 0 END) as isRead
FROM Notification
WHERE pkgName = :packagename
GROUP BY title;
如果要在表格中显示所有标题,而与软件包无关:
SELECT t.title, COUNT(n.title)
FROM (SELECT DISTINCT title FROM Notification) t LEFT JOIN
Notification n
ON n.title = p.title AND t.pkgName = :packagename AND
n.isRead = 0
GROUP BY t.title;
如果您有另一个包含所需标题列表的表,请使用该表代替t
的子查询。