In PostgreSQL i 想一劳永逸地向每个用户发出指示。
This is my query:
SELECT id, useridx, isread, message, date
FROM messages
WHERE isread = 1
GROUP BY useridx
ORDER BY date DESC
ample data:
------------------------------------------------------
+ id | useridx | isread | messsage | date +
------------------------------------------------------
1 | 1 | 0 | Hello | 2012-01-01
2 | 2 | 1 | Hi | 2012-01-02
3 | 3 | 1 | Test | 2012-01-03
4 | 3 | 0 | My Msg | 2012-01-04
5 | 4 | 1 | sadasd | 2012-01-05
6 | 4 | 1 | sdfsdfd | 2012-01-06
7 | 4 | 0 | sdfsdfsd | 2012-01-07
8 | 5 | 0 | 5345634 | 2012-01-08
9 | 6 | 0 | sdfdfsd | 2012-01-09
10 | 7 | 0 | sdfsdfsf | 2012-01-10
------------------------------------------------------
Now, what i want to do is fetch this table by grouping them via useridx and order by date.
<>Expected Result:
------------------------------------------------------
+ id | useridx | isread | messsage | date +
------------------------------------------------------
6 | 4 | 1 | sdfsdfd | 2012-01-06
3 | 3 | 1 | Test | 2012-01-03
2 | 2 | 1 | Hi | 2012-01-02
------------------------------------------------------
<>可见>
ERROR: column "messages.date" must appear in the GROUP BY clause or be used in an aggregate function
我不想混淆日期。 我只想把使用rid子组起来,并按日期分类。
感谢任何帮助/帮助!
http://www.ohchr.org。 不能满足我的需要,或者说错了。
www.un.org/Depts/DGACM/index_chinese.htm
Conclusion: For who get the same problem here can read this as an answer. Both @kgrittn s and @mu is too short s answers are correct. I will continue to use both answers and schemas on my project and in time i can understand which one is the best -i guess-. So, pick one of them and continue to your work. You will be just fine.
http://www.un.org。 排除一些女胎。 请允许我说,我有一栏id,我有6行。 因此,与BUT级(BUT)这一结果截然不同。 <>So,使用级别!