ClickHouse / ClickHouse/ClickHouse
Multiple sub query exceptions
- Dominant language
- C++
- Stars
- 49.9k
- Forks
- 9k
- Avg merge
- 21h 32m
- Merged PRs (30d)
- 515
Description
clickhouse:23.6.0
SELECT t1.AccountId AS AccountIdd
FROM (
SELECT g.AccountId,CAST(COALESCE(SUM(g.GrossProfit), 0) AS Decimal(32, 9)) AS c
FROM GP_ListingProfit AS g final
INNER JOIN (
SELECT s.AccountId, s.SiteId
FROM Shop AS s final
WHERE s.ShopId > 0
) AS t ON (g.AccountId = t.AccountId) AND (g.SiteID = t.SiteId)
INNER JOIN (
SELECT o.DayPeriod
FROM ODS_Base_CurrencyMonth AS o final
WHERE o.CurrencyName = 'CNY'
) AS t0 ON g.Period = t0.DayPeriod
WHERE ((g.SettlementTime >= '2023-09-01') AND (g.SettlementTime <= '2023-09-01'))
GROUP BY g.AccountId
) AS t1
INNER JOIN (
SELECT g0.AccountId
FROM GP_ListingProfit AS g0 final
INNER JOIN (
SELECT s0.AccountId, s0.SiteId
FROM Shop AS s0 final
WHERE s0.ShopId > 0
) AS t2 ON (g0.AccountId = t2.AccountId) AND (g0.SiteID = t2.SiteId)
INNER JOIN (
SELECT o0.DayPeriod
FROM ODS_Base_CurrencyMonth AS o0 final
WHERE o0.CurrencyName = 'CNY'
) AS t3 ON g0.Period = t3.DayPeriod
WHERE ((g0.SettlementTime >= '2023-09-01') AND (g0.SettlementTime <= '2023-09-01'))
GROUP BY g0.AccountId
) AS t4 ON t1.AccountId = t4.AccountId`
**error: [07000]: Code: 47. DB::Exception: There's no column 't1.AccountId' in table 't1': While processing t1.AccountId AS AccountIdd. (UNKNOWN_IDENTIFIER) (version 23.6.2.18 (official build))
, server ClickHouseNode [uri=http://clickhouse.bestwo.net:8123/default, options={use_server_time_zone=false,rename_response_column=REMOVE_PREFIX,use_time_zone=false}]@-1451334711**
**But the following query can be successful:**
SELECT t1.AccountId AS AccountIdd
FROM (
SELECT g.AccountId,CAST(COALESCE(SUM(g.GrossProfit), 0) AS Decimal(32, 9)) AS c
FROM GP_ListingProfit AS g final
INNER JOIN (
SELECT s.AccountId, s.SiteId
FROM Shop AS s final
WHERE s.ShopId > 0
) AS t ON (g.AccountId = t.AccountId) AND (g.SiteID = t.SiteId)
WHERE ((g.SettlementTime >= '2023-09-01' AND (g.SettlementTime <= '2023-09-01'))
GROUP BY g.AccountId
) AS t1
INNER JOIN (
SELECT g0.AccountId
FROM GP_ListingProfit AS g0 final
INNER JOIN (
SELECT s0.AccountId, s0.SiteId
FROM Shop AS s0 final
WHERE s0.ShopId > 0
) AS t2 ON (g0.AccountId = t2.AccountId) AND (g0.SiteID = t2.SiteId)
WHERE ((g0.SettlementTime >= '2023-09-01') AND (g0.SettlementTime <= '2023-09-01'))
GROUP BY g0.AccountId
) AS t4 ON t1.AccountId = t4.AccountId
**I found that if two tables are associated, there is no problem. If three tables are associated, there will be problems. The column names of the table will be automatically prefixed on the server. Although it can be solved by using AS, is this not feasible**
Contributor guide
Assessment
This issue has not been assessed yet.