Write a query below that retrieves the departure harbour, the departure date, the amount of voyages (rows) as column n, the minimum and maximum tonnage in each group (min_t/max_t) from the voyages table. Group by departure harbour and departure date. Filter out rows where departure harbour is NULL or equal to Batavia. Filter the groups to have at least two voyages in them.如何重命名此SQL片段中的多個列?
我很接近,但我不明白他們的意思與in each group (min_t/max_t)
什麼我需要做的呢?這是我應該得到的表...
# departure_harbour departure_date n min_t max_t
1 Batavia 1768 2 136 1150
而這就是我與我的查詢....
# departure_harbour departure_date MIN(tonnage) MAX(tonnage) n
1 NULL 1793 488 890 3
我有這樣的:
SELECT departure_harbour,
departure_date,
MIN(tonnage),
MAX(tonnage),
COUNT() AS n
FROM voyages
GROUP BY departure_harbour,
departure_date
HAVING departure_harbour IS NULL
OR departure_harbour = "Batavia"
當我在AS
之後聲明瞭min_t和max_t,它只是給了我錯誤。我不知道該怎麼做。除此之外:我如何更改表格中顯示的列的順序?
你得到了什麼錯誤信息? *你究竟如何嘗試對列進行別名? – Siyual
嗯,我試過(..)COUNT()AS n,max_t,min_t,但這給了我錯誤:查詢失敗:沒有這樣的列。 – Siyah
離開_哈寶有什麼問題? – xQbert