如何从数据库中的订单表按订单ID调用最后的订单

时间:2013-09-02 06:56:19

标签: php mysql

亲爱的,我需要根据表(数据库)的查询提供一些帮助:例如我有一个表" order_detail" 有一些文件

order_id    product_id    product_name    product_price    product_quantity
3           4  
3           5
4
5
6

现在我想在感谢页面中显示数据,其中包含order_id 3的所有信息。我怎么能从模型和控制器做到这一点???

4 个答案:

答案 0 :(得分:2)

第二个最大值:
    SELECT * FROM salary s ORDER BY s.value DESC LIMIT 1, 1
第二分钟:
    SELECT * FROM salary s ORDER BY s.value ASC LIMIT 1, 1

答案 1 :(得分:2)

通俗地说:

(
    SELECT salary
    FROM tblName
    ORDER BY salary DESC
    LIMIT 1
    OFFSET 1
)
UNION
(
    SELECT salary
    FROM tblName
    ORDER BY salary ASC
    LIMIT 1
    OFFSET 1
)

答案 2 :(得分:1)

第二个最高

SELECT salary_worth
FROM salary
WHERE salary_worth= (SELECT MAX(salary_worth) FROM salary WHERE salary_worth< (SELECT     MAX(salary_worth) FROM salary))

第二个最低

    SELECT salary_worth
    FROM salary
    WHERE salary_worth= (SELECT MIN(salary_worth) FROM salary WHERE salary_worth> (SELECT     MIN(salary_worth) FROM salary))

答案 3 :(得分:0)

我知道,这是过去的问题,但我来找下一个问题来解决问题:

SELECT * FROM (
    SELECT @w:=@w+1 AS der,salary_worth
        FROM salary, (SELECT @w:=0) AS del ORDER BY salary_worth) del2
   WHERE der IN (2,@w-1);