2012-03-10 67 views
0

我有這個疑問,我需要3列不是1列3行合併MySQL的語句轉換成3列不是3行

select count(*) from p_a a 
inner join p_aa aa on a.ID = aa.AlbumID 
where a.ID = '04c9ed6e-1fb2-4d49-b5f6-a9d227ad7e7d' 
union 
select count(*) from _ph p 
inner join pa a on a.ID = p.AlbumID 
where a.ID = '04c9ed6e-1fb2-4d49-b5f6-a9d227ad7e7d' 
union 
Select LastUpdate from tsimestamp ats where ats.AlbumID = '04c9ed6e-1fb2-4d49-b5f6-a9d227ad7e7d'; 

回答

2

返回一行你可以做這樣的:

select (select count(*) from p_a a inner join p_aa aa on a.ID = aa.AlbumID where a.ID = '04c9ed6e-1fb2-4d49-b5f6-a9d227ad7e7d'), 
     (select count(*) from _ph p inner join pa a on a.ID = p.AlbumID where a.ID = '04c9ed6e-1fb2-4d49-b5f6-a9d227ad7e7d'), 
     (select LastUpdate from tsimestamp ats where ats.AlbumID = '04c9ed6e-1fb2-4d49-b5f6-a9d227ad7e7d'); 
+0

謝謝,我忘記了逗號。謝謝!! – user516883 2012-03-10 06:44:54