Rumah > pangkalan data > tutorial mysql > 解决 船与运输问题

解决 船与运输问题

WBOY
Lepaskan: 2016-06-07 14:54:43
asal
1364 orang telah melayarinya

无详细内容 排座位 drop table v1;create table v1( name varchar(10), --人名, addres varchar(10) --去哪里,); insert into v1 values('my1','上海'); insert into v1 values('my2','北京'); insert into v1 values('my3','上海'); insert into v1 values('

排座位
drop table v1;
create table v1( 
name varchar(10),  --人名, 
addres varchar(10)  --去哪里,
); 
insert into v1 values('my1','上海'); 
insert into v1 values('my2','北京'); 
insert into v1 values('my3','上海'); 
insert into v1 values('my4','江西'); 
insert into v1 values('my5','上海'); 
select * from v1;
drop table v2;
create table v2( 
shipname varchar(10),  --船名, 
addres varchar(10)  --去哪里
); 
insert into v2 values('ship1','上海'); 
insert into v2 values('ship2','北京'); 
insert into v2 values('ship3','上海'); 
insert into v2 values('ship4','四川'); 
select * from v2;

select v1.name,v1.addres ,ROW_NUMBER() OVER(PARTITION BY v1.addres ORDER BY v1.addres DESC) AS 'RowNumber'
 from v1 order by v1.name;
 select v2.addres,v2.shipname ,ROW_NUMBER() OVER(PARTITION BY v2.addres ORDER BY v2.addres DESC) AS 'RowNumber'
 from v2  order by v2.addres;
 
 select x.name ,x.addres ,y.shipname  from (select v1.name,v1.addres ,ROW_NUMBER() OVER(PARTITION BY v1.addres ORDER BY v1.addres DESC) AS 'RowNumber'
 from v1) x left join (select v2.addres,v2.shipname ,ROW_NUMBER() OVER(PARTITION BY v2.addres ORDER BY v2.addres DESC) AS 'RowNumber'
 from v2) y on x.addres =y.addres and x.RowNumber=y.RowNumber
Salin selepas log masuk
解决 船与运输问题
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan