我有2张桌子
Table 1:
+-----+------+-------+
| ID | QTY | Name |
| 1 | 14 | Milk |
| 2 | 15 | Egg |
| 3 | 44 | Apple |
+-----+------+-------+
Table 2:
+-----+------+-------------+
| ID | QTY1 | Location |
| 1 | 5 | Food shelf |
| 2 | 6 | Food shelf |
| 3 | 8 | Food shelf |
+-----+------+-------------+
我想从QTY中删除QTY1,加入两个表并显示如下
Table 3:
+-----+-------+-----+-----+-------------+-------+
| ID | QTY | QTY1| SOLD| Location | Name |
| 1 | 14 | 5 | 9 | Food shelf | Milk |
| 2 | 15 | 6 | 9 | Food shelf | Egg |
| 3 | 44 | 7 | 37 | Food shelf | Apple |
+-----+-------+-----+-----+-------------+-------+
有什么办法吗?
答案 0 :(得分:0)
select t1.ID, t1.QTY, t2.QTY as "QTY1", (t1.QTY-t2.QTY) as "SOLD",
t2.Location, t1.Name
from table1 t1 inner join table2 t2 on t1.ID = t2.ID;
答案 1 :(得分:0)
您可以这样做
SELECT t1.ID, t1.QTY, t2.QTY AS QTY1, (t1.QTY - t2.QTY) AS SOLD, t2.Location, t1.Name
FROM table1 t1 inner join table2 t2 on t1.ID = t2.ID;
答案 2 :(得分:0)