1

sorry for the title, i don't know how to explain it better...

i have a forum and i want to make a sort of achievement system in php

i want to know when users with posts>10 posted their 10th message...

the post table is like

post_id | post_date | userid | post_message | ...

i can get this result for each user with

select userid, post_date from posts where userid=1 order by post_date limit 9,1

but i need a resultset like

id | date
id | date
id | date

it can only be done with procedures?

4

2 回答 2

1

试试这个查询

select 
    * 
from (
    select 
       @rn:=if(@prv=userid, @rn+1, 1) as rid, 
       @prv:=userid as userid,
       post_message
    from 
       tbl
    join 
       (select @rn:=0, @prv:=0) tmp
    order by 
       userid, 
       post_date) tmp 
where 
    rid=10

SQL 小提琴

| RID | USERID | POST_MESSAGE |
-------------------------------
|  10 |      1 |       asdasd |
|  10 |      2 |       asdasd |
于 2013-05-29T10:59:26.583 回答
1

试试这个:

SELECT userid
    , SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(post_date ORDER BY post_date), ',', 10), ',', -1) AS PostDate
    FROM posts
    GROUP BY userid
    HAVING PostDate <> '' OR PostDate IS NOT NULL

但是您需要注意GROUP_CONCAT可以容纳的最大长度。

于 2013-05-29T11:06:13.240 回答