How to connect these three mysql statements together

Source: Internet
Author: User
How to connect these three mysql statements to selectco_balance, forward (*) afromdt_staffwherestaff_shouye, and how to connect these three mysql statements together
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

Online !!!

------ Solution --------------------
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

Determine the query results of SQL statements a and B based on the type.
------ Solution --------------------
Select co_balance, co_isstaff, staff_group_id, count
From
(Select co_balance, co_isstaff from dt_co where co_id = 156),
(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.