使用group by后计算多列

时间:2016-12-26 02:16:38

标签: sql

我在查询中做了一些计数

enter image description here

我需要在分组后的不同条件下计数FLOW_ID两次:

select count(distinct flow_id) as work_sum,
       count(distinct case when ISHANDLE=2 THEN FLOW_ID) AS ERROR_SUM
       FROM Table A group by ALERT_USER

第一列是计算不同的flow_id, 第二个是计算不同的flow_id,其中列ISHANDLE = 2

但我的sql不起作用,任何人都可以帮忙吗? TKS

顺便说一句:我知道我可以写两个sqls并加入结果,但是我有另外一个类似的列,这将是太长了

2 个答案:

答案 0 :(得分:0)

大致正确,需要end case

select count(distinct flow_id) as work_sum,
       count(distinct (case when ISHANDLE=2 THEN FLOW_ID END)) AS ERROR_SUM
       FROM Table A group by ALERT_USER

答案 1 :(得分:0)

您可以使用IF功能。

File sdCard = Environment.getExternalStorageDirectory();
    String fileStr = sdCard.getAbsolutePath() + "/download";// +
                                                            // "app-release.apk";

    File file = new File(fileStr, "xadb-build.apk");

    if (file.exists()) {
        try {
            String command;
            command = "adb install -r " + file;
            Process proc = Runtime.getRuntime().exec(
                    new String[] { "su", "-c", command });
            proc.waitFor();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}