亲爱的,我需要根据从表(数据库)中查询的一些帮助:比如我有一个表“order_detail”,有一些文件
order_id product_id product_name product_price product_quantity
3 4
3 5
4
5
6
现在我想在感谢页面中显示包含 order_id 3 的所有信息的数据。我怎样才能从模型和控制器中做到这一点???
对于第二个最大值:
SELECT * FROM salary s ORDER BY s.value DESC LIMIT 1, 1
对于第二个最小值:
SELECT * FROM salary s ORDER BY s.value ASC LIMIT 1, 1
通俗地说:
(
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
)
第二个最大值
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))
我知道,这是过去的问题,但我来下一个查询是为了解决问题:
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);