由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 请教关于下面这个sql code地解释
相关主题
请教一个SQL query该怎么写help about SQL for ACCESS
最近写了不少SQL script,请大牛评价下属于什么水平求教(SQL/Access): Join两个query tables 出错
紧急求助, 关于SQL ServerCodes Re: 求教: Join 两个query (data)
SQL combine two tables into one table and add a new columnmysql doesn't support subquery still?
咋样选一个表中在另一个表中不含有的记录how to make this query
aks a simple SQL questionWhy is EXISTS generally faster than IN clause?
[转载] database for Linux?一个看似简单的sql语句
Re: recursive sql?感觉SQL里的
相关话题的讨论汇总
话题: table1话题: record话题: select话题: pear话题: cherry
进入Database版参与讨论
1 (共1页)
i********g
发帖数: 41
1
从网上看到这个关于select top N rows from each group的例子:
Let’s say I want to select the two cheapest fruits from each type. Here’s
a first try:
+--------+----------+-------+
| type | variety | price |
+--------+----------+-------+
| apple | gala | 2.79 |
| apple | fuji | 0.24 |
| orange | valencia | 3.59 |
| orange | navel | 9.36 |
| pear | bradford | 6.05 |
| pear | bartlett | 2.14 |
| cherry | bing | 2.55 |
| cherry | chelan | 6.33 |
+--------+----------+-------+
给出的sol
B*****g
发帖数: 34098
2
???
f 是水果表

s

【在 i********g 的大作中提到】
: 从网上看到这个关于select top N rows from each group的例子:
: Let’s say I want to select the two cheapest fruits from each type. Here’s
: a first try:
: +--------+----------+-------+
: | type | variety | price |
: +--------+----------+-------+
: | apple | gala | 2.79 |
: | apple | fuji | 0.24 |
: | orange | valencia | 3.59 |
: | orange | navel | 9.36 |

i********g
发帖数: 41
3
我刚改了原文,hehe,不过还是看不明白那个程序

【在 B*****g 的大作中提到】
: ???
: f 是水果表
:
: s

B*****g
发帖数: 34098
4
google “Subqueries”

【在 i********g 的大作中提到】
: 我刚改了原文,hehe,不过还是看不明白那个程序
C**********r
发帖数: 75
5
这种回复跟放屁一样

【在 B*****g 的大作中提到】
: google “Subqueries”
B*****g
发帖数: 34098
6
不一样,俺这个还有点用

【在 C**********r 的大作中提到】
: 这种回复跟放屁一样
k*******s
发帖数: 134
7
where f.type = fruits.type and f.price < fruits.price
fruits.type 和 fruits.price 指向的外层的fruit表,内层的fruit表已经被alias了
。所以单独run里面的sql会报错。
x***e
发帖数: 2449
8
This is a very difficult subquery.
It is hard to understand it even after you have been dealing with SQL for
years.
You can start with join/outerjoin and union first.
And try to rewrite join queries to subqueires and vice versa.
After a while, this one won't be that difficult to understand.

s

【在 i********g 的大作中提到】
: 从网上看到这个关于select top N rows from each group的例子:
: Let’s say I want to select the two cheapest fruits from each type. Here’s
: a first try:
: +--------+----------+-------+
: | type | variety | price |
: +--------+----------+-------+
: | apple | gala | 2.79 |
: | apple | fuji | 0.24 |
: | orange | valencia | 3.59 |
: | orange | navel | 9.36 |

b*****e
发帖数: 364
9
You will get three cheapest fruits if you use<=2.
You can understand it in this way. "Select" read database row by row. For
every row of data, it will get the logic true/false result in the "where"
clause. If true then output.
Hope this is helpful.

s

【在 i********g 的大作中提到】
: 从网上看到这个关于select top N rows from each group的例子:
: Let’s say I want to select the two cheapest fruits from each type. Here’s
: a first try:
: +--------+----------+-------+
: | type | variety | price |
: +--------+----------+-------+
: | apple | gala | 2.79 |
: | apple | fuji | 0.24 |
: | orange | valencia | 3.59 |
: | orange | navel | 9.36 |

b*****e
发帖数: 364
10
Here is another example of such kind of subquary.
if object_id('##Table1')<>0 drop table ##Table1
Create table ##Table1 (
[Record Value] varchar(20), [Record Date] smalldatetime
)
go
insert into ##Table1 values ('Record 1','07/21/2003')
insert into ##Table1 values ('Record 2','07/22/2003')
insert into ##Table1 values ('Record 3','07/23/2003')
insert into ##Table1 values ('Record 4','07/24/2003')
insert into ##Table1 values ('Record 5','07/25/2003')
insert into ##Table1 values ('Record 6',
1 (共1页)
进入Database版参与讨论
相关主题
感觉SQL里的咋样选一个表中在另一个表中不含有的记录
To get the 2nd, 3rd, 4th largest valueaks a simple SQL question
Please Help! ORA-00918: column ambiguously defined[转载] database for Linux?
Remove duplicate from oracle tableRe: recursive sql?
请教一个SQL query该怎么写help about SQL for ACCESS
最近写了不少SQL script,请大牛评价下属于什么水平求教(SQL/Access): Join两个query tables 出错
紧急求助, 关于SQL ServerCodes Re: 求教: Join 两个query (data)
SQL combine two tables into one table and add a new columnmysql doesn't support subquery still?
相关话题的讨论汇总
话题: table1话题: record话题: select话题: pear话题: cherry