将mysql语句组合成3列而不是3行

时间:2012-03-10 06:32:34

标签: mysql sql

我有这个查询,我需要返回一行有3列而不是1列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';

1 个答案:

答案 0 :(得分: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');