我有3个表名为productSaleStatus,productSalesVolume,productInfo
productSaleStatus表结构是
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| productCode | int(11) | YES | | NULL | |
| productName | varchar(10) | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
productSalesVolume表结构是
+-------------+-------+------+-------+------+-----------+--------------+
| productCode | sales | year | month | day | aFewWeeks | dayOfTheWeek |
+-------------+-------+------+-------+------+-----------+--------------+
| 1 | 100 | 2016 | 9 | 30 | 2 | 1 |
| 2 | 200 | 2016 | 10 | 30 | 2 | 1 |
| 1 | 150 | 2017 | 1 | 1 | 2 | 1 |
| 2 | 125 | 2017 | 1 | 2 | 2 | 1 |
+-------------+-------+------+-------+------+-----------+--------------+
productInfo表结构是
+-------------+------------------+-------------+
| productCode | optimumInventory | productDate |
+-------------+------------------+-------------+
| 1 | 500 | 2016-10-10 |
| 2 | 1000 | 2016-10-08 |
| 1 | 1500 | 2016-10-20 |
| 2 | 2000 | 2017-01-01 |
+-------------+------------------+-------------+
productSaleStatus的示例数据是
+-------------+-------------+
| productCode | productName |
+-------------+-------------+
| 1 | test |
| 2 | hello |
+-------------+-------------+
productSalesVolume的示例数据是
1, test, 150, 2017, 1, 1, 1500, 2016-10-20
2, hello, 125, 2017, 1, 2, 2000, 2017-01-01
productInfo的示例数据是
it "2" do
skip
puts "in A-2"
end
所以我想要的结果是
it "2", skip: true do
puts "in A-2"
end
有人可以给我写样本查询吗?
答案 0 :(得分:0)
根据您提供的示例数据,这应该会产生您想要的结果。虽然我认为您可能需要使用完整数据集添加group by
和总和sales
SELECT pi.ProductName, pss.sales, pss.month, pss.day, psv.optimumInventory, psv.productDate
FROM productSaleStatus pss
INNER JOIN productInfo pi
ON pss.productCode = pi.productCode
INNER JOIN productSalesVolume psv
ON pss.productCode = psv.productCode
WHERE pss.year = '2017'