gpt4 book ai didi

mysql - sql查询以获取具有折扣的季节性价格的产品

转载 作者:太空宇宙 更新时间:2023-11-03 11:28:06 25 4
gpt4 key购买 nike

我有这个季节表

+----+------------+------------+------------+-------+------+----------+------------+------------+------------+
| id | base_price | startDate | endDate | cost | type | Duration | product_id | created_at | updated_at |
+----+------------+------------+------------+-------+------+----------+------------+------------+------------+
| 1 | 100.00 | 1537390800 | 1538773200 | 95.00 | day | 2 | 9 | NULL | NULL |
| 2 | 100.00 | 1537390800 | 1538773200 | 85.00 | day | 3 | 9 | NULL | NULL |
| 3 | 100.00 | 1537390800 | 1538773200 | 75.00 | day | 4 | 9 | NULL | NULL |
| 4 | 100.00 | 1537390800 | 1538773200 | 70.00 | day | 5 | 9 | NULL | NULL |
+----+------------+------------+------------+-------+------+----------+------------+------------+------------+

和产品表

+----+----------------------------+-----------+-----+-------+---------+--------------+---------------------+---------------------+---------------------+
| id | alias | status | img | price | user_id | published_at | deleted_at | created_at
| updated_at |
+----+----------------------------+-----------+-----+-------+---------+--------------+---------------------+---------------------+---------------------+
| 8 | toyota-corolla-1-6-elegant | draft | 18 | 30 | 1 | 2018-08-14 | NULL | 2018-08-14 15:06:12 | 2018-08-20 14:58:18 |
| 9 | test | published | | 0 | 1 | 2018-08-23 | 2018-09-10 19:44:29 | 2018-08-23 14:45:18 | 2018-09-10 19:44:29 |
+----+----------------------------+-----------+-----+-------+-------

现在我试试这个sql

SELECT *
FROM products,
(SELECT *
FROM season
WHERE Duration = ( SELECT MAX(Duration) FROM ec_season WHERE `Duration` <= 3)
) as t1
LEFT OUTER JOIN t1
ON t1.product_id = products.id

但它给了我

1146 - 表 '****.t1' 不存在

如何将产品附加到t1?

最佳答案

试试这个:你的连接语法不正确

SELECT *
FROM products left outer join
(SELECT *
FROM season
WHERE Duration = ( SELECT MAX(Duration) FROM ec_season WHERE `Duration` <= 3)
) as t1 ON t1.product_id = products.id

关于mysql - sql查询以获取具有折扣的季节性价格的产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52498636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com