I am trying to build a query which supports conditional group by in SQLite DB.

Here is what I tried so far:

```
SELECT 
      case 
       when A>1 AND B>1 THEN 1
       when X>1 AND Y>1 THEN 2
       when C>1 AND D>1 THEN 3
      END AS data_grp,
     SUM(col1) AS col1,
     SUM(col2) AS col2
FROM tbl
GROUP BY data_grp;

```

This Works pretty fine if only single case is true at a time. if multiple cases are true in a row then it returns the first case instead of all satisfying groups.

I have tried this by the `union` which works well but very slow. Is there any other way to fetch results fast with this conditional group.

**Sample Data & Expected results:**

```
DROP TABLE IF EXISTS  tbl;
CREATE TABLE tbl
(
    A INT,
    B INT,
    C INT,
    D INT,
    X INT,
    Y INT,
    col1 int,
    col2 int

);

INSERT INTO tbl(A,B,C,D,X,Y,col1,col2) values (2,3,0,0,0,0,5,10);
INSERT INTO tbl(A,B,C,D,X,Y,col1,col2) values (0,0,0,0,8,10,3,2);
INSERT INTO tbl(A,B,C,D,X,Y,col1,col2) values (5,4,4,9,0,0,3,2);

    SELECT 
          case 
           when A>1 AND B>1 THEN 1
           when X>1 AND Y>1 THEN 2
           when C>1 AND D>1 THEN 3
          END AS data_grp,
         SUM(col1) AS col1,
         SUM(col2) AS col2
    FROM tbl
    GROUP BY data_grp;

```

**Query Output :**

```
"1" "8" "12"
"2" "3" "2"

```

**Expected Output :**

```
"1" "8" "12"
"2" "3" "2"
"3" "3" "2"

```