SQL问题! [英] SQL Problem!

查看:65
本文介绍了SQL问题!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个让我感到困惑的SQL分配问题!我需要帮助...

问题如下.

在具有产品名称,价格,类别描述等字段的名为product的表中,找到product表中第二低的单价并显示产品名称.

我想出了以下代码来获取第二低的单价,但我需要执行另一个嵌套查询以返回产品说明.

选择最小值(单价)
来自tblProduct
其中单价<> (从tblProduct中选择min(UnitPrice))

I have an SQL assignment question that stumps me! I need help...

The question is as follows.

From a table called product that has fields such as product name, price, category description, find the second lowest unitprice in the product table and display the products name.

I''ve come up with the following code to get the second lowest unitprice but I need to do another nested query to return the product description.

Select min(UnitPrice)
From tblProduct
Where UnitPrice <> (Select min(UnitPrice) from tblProduct)

How do I do this????

推荐答案

看看这个:http://msdn.microsoft.com/en-us/library/ms176102.aspx [

samcro试试这个

从tblProduct P1中选择单价,描述
其中2 =(从tblProduct P2中选择Count(*)
其中P1.UnitPrice> = P2.UnitPrice)


如果您想第二大的话,请< =

希望这能解决您的问题.
hi samcro try this one

Select UnitPrice,description From tblProduct P1
Where 2=(Select Count(*) From tblProduct P2
Where P1.UnitPrice >= P2.UnitPrice)


if you want second largest then make <=

hope this will solve your problem.


这篇关于SQL问题!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆