數(shù)據(jù)結(jié)構(gòu)是這樣的date | not uniquser | not uniqproduct | uniq我要做這樣一個查詢?nèi)〕鏊杏脩簦罱l(fā)出的一個產(chǎn)品,并且這個列表是按照date排序的。比如數(shù)據(jù)如下--
date | user | product20120901 | John | A20120903 | Tom | B20120802 | John | C20120906 | John | D20120821 | Tom | E20120902 | Tom | F20120825 | Tom | G我希望得到數(shù)據(jù)--
date | user | product | count20120906 | John | D | 320120903 | Tom | B | 4我寫的SQL如下:Cursor cursor = db.query( /* FROM */ "products", /* SELECT */ new String[]{ "*", "COUNT(product) AS count" }, /* WHERE */ null, /* WHERE args */ null, /* GROUP BY */ "user", /* HAVING */ null, /* ORDER BY */ "date DESC");
1 回答

鴻蒙傳說
TA貢獻1865條經(jīng)驗 獲得超7個贊
having可以理解為group by的where條件
不知道你這個ORM怎么寫,直接寫sql,在mysql下測試通過:
select a.*,count(a.product) as count from products a where date=(select max(date) from products b where b.user=a.user) group by user
- 1 回答
- 0 關(guān)注
- 270 瀏覽
添加回答
舉報
0/150
提交
取消