简体   繁体   中英

Ambiguous column name when using alias in join

Why does this query produce an "Ambiguous column name" error when I include the "as time" alias? If I remove "as time" or "SAMPLE BY 1d", it goes away.

SELECT a.ts as time, sum(a.to_grid), sum(a.from_grid), sum(b.hourly_production)
FROM 'eloverblik' as a, 'ap_systems' as b
WHERE a.ts = b.ts
SAMPLE BY 1d;

Edit: The schemas are:

ap_systems
  ts timestamp
  hourly_production double

eloverblik
  ts timestamp
  to_grid double
  from_grid double

Edit2: The following query using another alias and join syntax have the same issue

SELECT e.ts as timecol, sum(e.to_grid), sum(e.from_grid), sum(a.hourly_production)
FROM 'eloverblik' as e INNER JOIN 'ap_systems' as a ON
 (e.ts = a.ts)
SAMPLE BY 1d;

time is a reserved keyword, use another name such as timestamp .
Rename the aliases to something more descriptive, but short.
Use JOIN syntax.
These solutions were essentially recommended in the comments by umadik and Honeybadger .

SELECT e.ts as timestamp, sum(e.to_grid) as sum_to_grid, sum(e.from_grid) as sum_from_grid, sum(a.hourly_production) as sum_hourly_production
FROM 'eloverblik' as e INNER JOIN 'ap_systems' as a ON
     (e.ts = a.ts)
SAMPLE BY 1d;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM