Heim  >  Artikel  >  Backend-Entwicklung  >  怎样将这三条mysql语句连到一起去解决方案

怎样将这三条mysql语句连到一起去解决方案

WBOY
WBOYOriginal
2016-06-13 13:51:45813Durchsuche

怎样将这三条mysql语句连到一起去
select co_balance,co_isstaff from dt_co where co_id=156

select staff_group_id from dt_staff where co_id = 156

select count(*) a from dt_staff where staff_shouyetuijian = 1 and co_id = 156

在线等!!!

------解决方案--------------------
SELECT co_balance AS a,co_isstaff AS b,1 AS TYPE FROM dt_co WHERE co_id=156

UNION ALL 

SELECT staff_group_id AS a, '' AS b, 2 AS TYPE FROM dt_staff WHERE co_id = 156

UNION ALL

SELECT COUNT(*) AS a, '' AS b, 3 AS TYPE FROM dt_staff WHERE staff_shouyetuijian = 1 AND co_id = 156

根据type判断a,b分别sql的查询结果
------解决方案--------------------
select co_balance,co_isstaff,staff_group_id,count 
from 
(select co_balance,co_isstaff from dt_co where co_id=156) a,
(select staff_group_id from dt_staff where co_id = 156) b,
(select count(*) as count from dt_staff where staff_shouyetuijian = 1 and co_id = 156) c

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn