第一个查询语句中,子查询中用WHERE type=U.type和外部的查询限定。而第二个查询语句中,子查询中是条件是固定的,SELECT MIN(price) FROM dbo.titles WHERE type='trad_cook' ,这个子查询固定返回11.95。
解决方案 »
- 统计问题
- SQL不能实现想要的结果。
- 愁死人的问题?
- 数据库同步 创建‘发布’时出错! 错误0:此服务器已经断开。必须重新连接以执行此操作。
- sql翻页查询中加去重复数据查询怎么做啊
- 如何处理这样的存储过程
- 这个sql语句如何写?对高手来说就是送分题了^_^
- 大GG给小女子看看这个sql怎么回事??
- Wingsun,please come in!I want a futher question about visit sql7 from unix!
- 在asp,net中与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。
- 大家好,我是新来的,请多多指教
- 这个SQL查询应该怎么写?
SELECT type, title, price
FROM dbo.titles AS U
WHERE price=(
SELECT MIN(price) FROM dbo.titles WHERE type=U.type
)
SELECT type, title, price
FROM dbo.titles AS U
WHERE price=(
SELECT MIN(price) FROM dbo.titles WHERE type='trad_cook' )
SELECT type, title, price
FROM dbo.titles AS U
WHERE price=(
SELECT MIN(price) FROM dbo.titles WHERE type=U.type and type='trad_cook' )
我可能没说清楚:第一个查询语句中,子查询中用WHERE type=U.type和外部的查询限定。
这个限定是不是说:外部的查询变量U.type将取值business。SQL Server 将该值代入到内部查询中
SELECT type, title, price
FROM dbo.titles AS U
WHERE price=(
SELECT MIN(price) FROM dbo.titles WHERE type='business' )
结果为2.9900 ,所以外部查询评估为:
SELECT type, title, price
FROM dbo.titles AS U
WHERE price=(
2.9900
)
依次类推
***************如果我对上面的理解是对的***************************'trad_cook' 时呢?????
怎样去掉business类型的11.9500的????????????
-------------------------------------------根据外部的type变化而变化,不是固定的business
wangtiecheng说根据外部的type变化而变化,不是固定的business,那它也是一个一个的送入的数据。
向第一次是business类型,第二次trad_cook类型,等等。
它的内查询每次返回的是一个数值。外查询使用着个数值在查找。
'trad_cook' 类型的最小值是11.9500,并把它给外查询。
外查询根据这个值(11.9500)查找。
这时business类型有一个值是11.9500
trad_cook类型有一个值是11.9500为什么business被数据库去掉了?????????
type title price
-----------------------------------------------------------------------
business You Can Combat Computer Stress! 2.9900
mod_cook The Gourmet Microwave 2.9900
popular_comp Secrets of Silicon Valley 20.0000
psychology Life Without Fear 7.0000
trad_cook Fifty Years in Buckingham Palace Kitchens 11.9500不明白楼主意思
business类的最低价是2.9900 不是11.9500如果把business类的低于11.9500的价格全部改成大于11.9500的那结果就是type title price
-----------------------------------------------------------------------
business You Can Combat Computer Stress! type title price
-----------------------------------------------------------------------
business You Can Combat Computer Stress! 11.9500
mod_cook The Gourmet Microwave 2.9900
popular_comp Secrets of Silicon Valley 20.0000
psychology Life Without Fear 7.0000
trad_cook Fifty Years in Buckingham Palace Kitchens 11.9500
mod_cook The Gourmet Microwave 2.9900
popular_comp Secrets of Silicon Valley 20.0000
psychology Life Without Fear 7.0000
trad_cook Fifty Years in Buckingham Palace Kitchens 11.9500不知道我的理解是不是对的?
SELECT type, title, price
FROM dbo.titles AS U
WHERE price=( SELECT MIN(price) FROM dbo.titles WHERE type='trad_cook')
and type='trad_cook'
FROM dbo.titles AS U
WHERE not exists(
SELECT 1 FROM dbo.titles WHERE type=U.type and price<a.price
)
and type='trad_cook'--在这里限制