如何在一个表中包含多个选择语句 [英] How to include multiple select statements in one table

查看:35
本文介绍了如何在一个表中包含多个选择语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Select count(Gender)  as 'FOScout' from stormtroopers_officer join st_officer_assign on stormtroopers_officer.STID=st_officer_assign.STID where Gender='Female';
SELECT count(Gender)  as 'FNScout' from stormtroopers_nco join st_nco_assign on stormtroopers_nco.STID=st_nco_assign.STID where Gender='Female';
SELECT count(Gender)  as 'FTScout' from stormtroopers_troop join st_troop_assign on stormtroopers_troop.STID=st_troop_assign.STID where Gender='Female';
Select count(Gender)  as 'MOScout' from stormtroopers_officer join st_officer_assign on stormtroopers_officer.STID=st_officer_assign.STID where Gender='male';
SELECT count(Gender)  as 'MNScout' from stormtroopers_nco join st_nco_assign on stormtroopers_nco.STID=st_nco_assign.STID where Gender='male';
SELECT count(Gender)  as 'MTScout' from stormtroopers_troop join st_troop_assign on stormtroopers_troop.STID=st_troop_assign.STID where Gender='male';
SELECT count(Gender)  as 'Total Female Scouts' from stormtroopers_troop WHERE Gender = 'Female';
SELECT count(Gender)  as 'Total Male Scouts' from stormtroopers_troop WHERE Gender='Male';
SELECT count(Gender)  as 'Total Male Scouts' from stormtroopers_troop;

当我执行此操作时,它显然会放在单独的表中,而我想要的是将它们放在一张表中,如这张图片所示

When I execute this obviously it will come in separate tables, while what I want is to put them in one table as shown in this pic

推荐答案

将查询更改为:

SELECT
(Select count(Gender)  as 'FOScout' from stormtroopers_officer join st_officer_assign on stormtroopers_officer.STID=st_officer_assign.STID where Gender='Female') as 'FOScout',
(SELECT count(Gender)  as 'FNScout' from stormtroopers_nco join st_nco_assign on stormtroopers_nco.STID=st_nco_assign.STID where Gender='Female') as 'FNScout',
(SELECT count(Gender)  as 'FTScout' from stormtroopers_troop join st_troop_assign on stormtroopers_troop.STID=st_troop_assign.STID where Gender='Female') as 'FTScout',
(Select count(Gender)  as 'MOScout' from stormtroopers_officer join st_officer_assign on stormtroopers_officer.STID=st_officer_assign.STID where Gender='male') as 'MOScout',
(SELECT count(Gender)  as 'MNScout' from stormtroopers_nco join st_nco_assign on stormtroopers_nco.STID=st_nco_assign.STID where Gender='male') as 'MNScout',
(SELECT count(Gender)  as 'MTScout' from stormtroopers_troop join st_troop_assign on stormtroopers_troop.STID=st_troop_assign.STID where Gender='male') as 'MTScout',
(SELECT count(Gender)  as 'Total Female Scouts' from stormtroopers_troop WHERE Gender = 'Female') as 'Total Female Scouts',
(SELECT count(Gender)  as 'Total Male Scouts' from stormtroopers_troop WHERE Gender='Male') as 'Total Male Scouts',
(SELECT count(Gender)  as 'Total Male Scouts' from stormtroopers_troop) as 'Total Male Scouts'

这篇关于如何在一个表中包含多个选择语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆