SQL-选择具有多个where的AS

时间:2015-06-14 00:23:04

标签: mysql

我想将SQL查询的输出显示如下。

| COUNT_A | COUNT_B | COUNT_C | COUNT_D |

| 2 | 3 | 4 | 5 |

我使用UNION ALL获得的当前输出是

| COUNT_A |

2
3
4
5

var element = $(".element"); 
        $(window).scroll(function () {
            var scroll = $(window).scrollTop();
            for(var i = 0; i < element.length;i++){
                if(scroll > element.eq(i)){
                    element.eq(i).addClass("newClass");
                }
   }
})

我可以请求别人的帮助。我不擅长这个。

1 个答案:

答案 0 :(得分:0)

SELECT t1.COUNT_A, t2.COUNT_B,t3.COUNT_C,t4.COUNT_D FROM
(SELECT COUNT(INS_NAME) as COUNT_A from table_A where INS_NAME IN ( SELECT INS_NAME from table_B WHERE INS_ID IN (SELECT INS_MAP_ID FROM TEN_TO_INST_MAP where T_IN_MAP_ID = (SELECT T_ID FROM TW WHERE TNAM = 'abc'))) AND T_DATE between '2015-01-01' and '2015-07-01' AND INS_NAME NOT LIKE 'x%pr%' AND INS_NAME like 'x%y%' AND AND INS_NAME not like 'x%y%z') t1
,
(SELECT COUNT(INS_NAME) as COUNT_B from table_A where INS_NAME IN ( SELECT INS_NAME from table_B WHERE INS_ID IN (SELECT INS_MAP_ID FROM T_IN_MAP where T_IN_MAP_ID = (SELECT T_ID FROM TW WHERE TNAM = 'abc'))) AND T_DATE between '2015-01-01' and '2015-07-01' AND INS_NAME NOT LIKE 'x%pr%' AND INS_NAME like 'x%as%') t2
,
(SELECT COUNT(INS_NAME) as COUNT_C from table_A where INS_NAME IN ( SELECT INS_NAME from table_B WHERE INS_ID IN (SELECT INS_MAP_ID FROM T_IN_MAP where T_IN_MAP_ID = (SELECT T_ID FROM TW WHERE TNAM = 'abc'))) AND T_DATE between '2015-01-01' and '2015-07-01' AND INS_NAME NOT LIKE 'x%pr%' AND INS_NAME like 'x%dfg%') t3
,
(SELECT COUNT(INS_NAME) as COUNT_C from table_A where INS_NAME IN ( SELECT INS_NAME from table_B WHERE INS_ID IN (SELECT INS_MAP_ID FROM T_IN_MAP where T_IN_MAP_ID = (SELECT T_ID FROM TW WHERE TNAM = 'abc'))) AND T_DATE between '2015-01-01' and '2015-07-01' AND INS_NAME NOT LIKE 'x%pr%' AND INS_NAME like 'x%y%z') t4