dreamfly0514 2016-04-03 06:26
浏览 35
已采纳

到达行时查询mysql然后停止? 显示队列号

I am doing a script want to calculate how many row record before an user record when t1.status is 1.

My table is t1, and the data as below:

+------+---------+------------+----------+----------+
| ID   | name    | desc       | status   | time     |
+------+---------+------------+----------+----------+
| 1    | ABB     |            | 1        | 0325     |
| 2    | CCD     |            | 1        | 0236     |
| 3    | EEF     |            | 1        | 0325     |
| 4    | GGG     |            | 1        | 0000     |
| 5    | HIJ     |            | 2        | 1234     |
| 6    | KKK     |            | 1        | 5151     |
+---------------------------------------------------+

I was thinking about the query is something like (query row where status = 1 AND stop when reach $userid)

I would like to output to show user (Let's say username is GGG) as: $userid = 'GGG';

then my output will be

<table><tr><td>Queue: GGG You came in 4 place, in front of you still got 3 person in queue, please be patient</td></tr></table>

How to I do the right query to get the number 4 and 3 ?

Thank you.

  • 写回答

1条回答 默认 最新

  • doulieyu0881 2016-04-03 06:55
    关注

    You can try something like this hope it helps :-

    SELECT count(*) as COUNT FROM t1 WHERE id < (SELECT id FROM t1 WHERE userid = $userid)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条