-3

亲爱的,我需要根据从表(数据库)中查询的一些帮助:比如我有一个表“order_detail”,有一些文件

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

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

4

4 回答 4

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

于 2013-09-02T07:00:11.097 回答
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
)
于 2013-09-02T07:00:22.317 回答
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))
于 2013-09-02T07:01:18.310 回答
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);
于 2013-09-06T07:39:39.313 回答