MariaDB [Test]> select * from oo;
+---------------------+------+
| dte | flg |
+---------------------+------+
| 2019-07-03 10:00:00 | 1 |
| 2019-07-03 10:26:11 | 0 |
| 2019-07-03 10:30:05 | 2 |
| 2019-07-03 10:31:05 | 0 |
| 2019-07-03 10:50:44 | 1 |
| 2019-07-03 10:59:01 | 2 |
| 2019-07-03 11:11:11 | 1 |
| 2019-07-03 11:54:56 | 0 |
| 2019-07-03 12:34:05 | 2 |
| 2019-07-03 12:44:05 | 2 |
| 2019-07-03 13:09:05 | 2 |
+---------------------+------+
11 rows in set (0.00 sec)
MariaDB [Test]> SELECT flg,COUNT(flg) AS icnt FROM oo where dte > '2019-07-03 10:00:00' and dte < '2019-07-03 12:00:00' GROUP BY flg;
+------+------+
| flg | icnt |
+------+------+
| 0 | 3 |
| 1 | 1 |
| 2 | 3 |
+------+------+
3 rows in set (0.00 sec)
ถ้าหากผมต้องการหาผลลบ ของ icnt 3-1 ต้องเรียงคำสั่งยังไงหรอคับ
ถามเรื่อง SQL เหมือนเดิม
+---------------------+------+
| dte | flg |
+---------------------+------+
| 2019-07-03 10:00:00 | 1 |
| 2019-07-03 10:26:11 | 0 |
| 2019-07-03 10:30:05 | 2 |
| 2019-07-03 10:31:05 | 0 |
| 2019-07-03 10:50:44 | 1 |
| 2019-07-03 10:59:01 | 2 |
| 2019-07-03 11:11:11 | 1 |
| 2019-07-03 11:54:56 | 0 |
| 2019-07-03 12:34:05 | 2 |
| 2019-07-03 12:44:05 | 2 |
| 2019-07-03 13:09:05 | 2 |
+---------------------+------+
11 rows in set (0.00 sec)
MariaDB [Test]> SELECT flg,COUNT(flg) AS icnt FROM oo where dte > '2019-07-03 10:00:00' and dte < '2019-07-03 12:00:00' GROUP BY flg;
+------+------+
| flg | icnt |
+------+------+
| 0 | 3 |
| 1 | 1 |
| 2 | 3 |
+------+------+
3 rows in set (0.00 sec)
ถ้าหากผมต้องการหาผลลบ ของ icnt 3-1 ต้องเรียงคำสั่งยังไงหรอคับ