使用多个排序列并且这些列的顺序发生变化时输出会发生变化是否正常?
例如:
create table test_table (
id int8 not null,
year int4 not null,
province varchar(16) not null,
dangerous bool,
sector varchar(9) not null,
unit varchar(3) not null,
amount numeric not null
);
insert into test_table (id, year, province, dangerous, sector, unit, amount) values (1, 2012, 'W_FL', true, 'FOTOG', 'TNE', 55);
insert into test_table (id, year, province, dangerous, sector, unit, amount) values (2, 2012, 'E_FL', true, 'CHEM', 'TNE', 54);
insert into test_table (id, year, province, dangerous, sector, unit, amount) values (3, 2012, 'W_FL', true, 'CHEM', 'TNE', 74);
insert into test_table (id, year, province, dangerous, sector, unit, amount) values (4, 2012, 'E_FL', true, 'FOTOG', 'TNE', 4);
insert into test_table (id, year, province, dangerous, sector, unit, amount) values (5, 2012, 'LIM', true, 'FOTOG', 'TNE', 4);
第一个查询:
select
*
from
test_table test
where
test.year=2012
order by
test.province asc,
test.sector asc
limit 2;
哪个输出:
ID YEAR PROVINCE DANGEROUS SECTOR UNIT AMOUNT
2 2012 E_FL TRUE CHEM TNE 54
4 2012 E_FL TRUE FOTOG TNE 4
第二个查询:
select
*
from
test_table test
where
test.year=2012
order by
test.sector asc,
test.province asc
limit 2;
此查询返回其他内容:
ID YEAR PROVINCE DANGEROUS SECTOR UNIT AMOUNT
2 2012 E_FL TRUE CHEM TNE 54
3 2012 W_FL TRUE CHEM TNE 74
就好像限制只使用了第二个 order by 子句......有人可以验证我的假设,即两个查询应该产生相同的输出吗?