ClickHouse/tests/queries/0_stateless/03240_cte_in_subquery.sql

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
801 B
MySQL
Raw Normal View History

2024-09-23 17:11:33 +00:00
SET enable_analyzer = 1;
2024-09-22 21:19:42 +00:00
DROP TABLE IF EXISTS subquery_cte_in;
CREATE TABLE subquery_cte_in
(
`date` DateTime64(3),
`label` UInt32,
`id` UInt32
)
ENGINE = MergeTree
ORDER BY (label, id, date);
INSERT INTO subquery_cte_in VALUES (toDateTime('2023-10-24 16:13:38'), 2, 6), (toDateTime('2023-10-24 16:00:00'), 2, 10), (toDateTime('2023-10-24 00:00:00'), 2, 6);
SELECT max(date_out)
FROM
(
WITH
(
SELECT max(date)
FROM subquery_cte_in
WHERE (id = 6) AND (label = 2)
) AS cte_1,
(
SELECT max(date)
FROM subquery_cte_in
WHERE (id = 10) AND (label = 2)
) AS cte_2
SELECT date AS date_out
FROM subquery_cte_in
WHERE date IN (cte_1, cte_2)
);
DROP TABLE subquery_cte_in;