【发布时间】:2020-12-20 15:49:13
【问题描述】:
CREATE TABLE operations (
id int auto_increment primary key,
time_stamp DATE,
product VARCHAR(255),
plan_week VARCHAR(255)
);
INSERT INTO operations
(time_stamp, product, plan_week
)
VALUES
("2020-01-01", "Product_A", "CW01"),
("2020-01-01", "Product_B", "CW01"),
("2020-01-01", "Product_C", "CW01"),
("2020-03-15", "Product_A", "CW01"),
("2020-03-15", "Product_B", "CW02"),
("2020-03-15", "Product_C", "CW02"),
("2020-03-15", "Product_D", "CW01");
预期结果
product week_switch
Product_A no
Product_B yes
Product_C yes
Product_D no
在上面的结果中,我想检查一个产品的plan_week 是否从一个time_stamp 切换到另一个time_stamp。
如果满足条件yes 应用作值。如果不是no,则应插入。
SELECT
product
FROM operations
GROUP BY 1;
我不知道我需要什么样的查询来实现这一点。 你有什么想法吗?
【问题讨论】:
标签: mysql sql group-by max min