我想比较一个表中的两行。检索特定年份的第2行值小于同一年的第1行值的记录:
Year Line Dollar
2001 1 $50
2001 2 $50
2002 1 $100
2002 2 $100
2003 1 $150
2003 2 $100
结果是
Year Line Dollar
2003 1 $150
2003 2 $100
由于
答案 0 :(得分:2)
select a.*, b.*
from yourtable a, yourtable b
where a.year = b.year
and a.line = 1
and b.line = 2
and a.dollar > b.dollar