我需要显示别名表的SUM值,该值具有乘以2个字段的结果值。
这是资产表:
::after
我已经尝试过:
+----------+-----+------------+
| price | qty | tanggal |
+----------+-----+------------+
| 6775000 | 1 | 2019-03-30 |
| 4760000 | 2 | 2019-03-25 |
| 7800000 | 2 | 2019-04-01 |
| 13599000 | 1 | 2019-03-30 |
+----------+-----+------------+
也使用BETWEEN子句:
SELECT
SUM((price*qty))
AS worth
FROM asset
WHERE DATE(tanggal) >= 2019-03-25 AND DATE(tanggal) <= 2019-03-30
它一直为我提供 NULL 值,但是如果我删除了
SELECT SUM((price*qty)) AS worth FROM asset WHERE DATE(tanggal) BETWEEN 2019-03-25 AND 2019-03-30
子句, 可以正常工作,给我的值是 45494000 。有什么想法吗?
答案 0 :(得分:2)
添加单引号怎么样,知道您只是在做减法
SELECT SUM((price*qty)) AS worth
FROM asset
WHERE tanggal >= '2019-03-25' AND tanggal <= '2019-03-30'