简体   繁体   English

MSAccess 2007 SQL复杂查询

[英]MSaccess 2007 SQL complex query

I have the following table columns and values... 我有以下表格列和值...

ColA, ColB, ColC
b, 90, 1
p, 95, 5
p, 100, 6
p, 99, 6
p, 98, 6
b, 94, 5
b, 93, 1
b, 92, 3
o, 89, 3
b, 88, 4

I need the following result set: 我需要以下结果集:

ColA, ColB, ColC
b, 90, 1
b, 93, 1
p, 95, 5
o, 89, 3

Essentially, this is the lowest value for ColC where ColA is the same. 本质上,这是ColA相同的ColC的最小值。 So the lowest value for all the b's is 1, and it occurs in two rows. 因此,所有b的最小值是1,它出现在两行中。 The lowest value for all the p's is 5, and the lowest value for all the o's is 3. ColB is a value to join on another table. 所有p的最小值是5,所有o的最小值是3。ColB是要在另一个表上联接的值。 So I do need a query that will join on another table over ColB. 所以我确实需要一个查询,该查询将通过ColB联接到另一个表上。

Thanks. 谢谢。

Try This 尝试这个

select mainTable.* from abcTable as mainTable inner join 
(select t.colA,min(t.colC) as minColC from  abcTable as t group by t.ColA) as minimumTable
on mainTable.colA=minimumTable.ColA and mainTable.colC=minimumTable.minColC

Here you go! 干得好!

with r1 as
(select *
,rank() over (partition by ColA order by ColC) fix
from aba
)

select * from r1 where fix = 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM