douduan2272 2017-11-21 16:31
浏览 22

PHP,MySQL - 在特定产品的竞标中找到产品的位置

I have a bid table:

id | product_id | price | quantity | user_id | created_at

I need to select all the bids for the selected user and show the bid position in comparison for the same product. This is an example of result I need (I need to order it by created_at).

Product 2 - 22$ - 100p - Position 3
Product 2 - 33$ - 100p - Position 1
Product 3 - 2$  - 100p - Position 7
Product 2 - 30$ - 100p - Position 2
Product 4 - 69$ - 100p - Position 4....

As you see results are not linear since the user will get bids for different products and random time. Is this possible to do with a single query?

  • 写回答

3条回答 默认 最新

  • dongquxiao8545 2017-11-21 16:37
    关注

    Using the order by select statement

    Select * FROM database WHERE product_id = your_product ORDER by PRICE 
    

    you can then use ASC or DSC on end to put in different orders

    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失