开发者

Need two solution for fast algorithms

I got a bids table (different users). each user can place his bids (unlimited) whenever he wants to.

I need to apply two rules that should cancel bids: first rule - no more than 4 consecutive bids , which means if the user have: 10.50 10.47 10.36 10.20 10.00 so 10.00 should be canceled.

second rule is no more than 9 bids among top 50 bids, again, the 10th should be canceled.

I do it the really long way, just running on the bids table and counting for consecutives. But I would like to know if someone has other idea... (php开发者_开发问答 + mysql)

Thanks


For the second criteria:

SELECT username, count(*) as bids
FROM 
  (SELECT username
  FROM bids
  ORDER BY bid_timestamp DESC
  LIMIT 50)
WHERE username = :username
GROUP BY username
HAVING COUNT(*) > :bid_limit

If this record returns any rows, then disallow the new bid. Probably a better way to do this but it's better than returning all 50 rows to php and then iterating through and counting.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜