步驟 5:使用查詢編輯器嘗試範例查詢 - Amazon Redshift

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

步驟 5:使用查詢編輯器嘗試範例查詢

若要設定和使用 Amazon Redshift 查詢編輯器 v2 來查詢資料庫,請參閱 Amazon Redshift 管理指南中的使用查詢編輯器 v2

現在,嘗試一些範例查詢,如下所示。如需使用 SELECT 命令的詳細資訊,請參閱 Amazon Redshift 資料庫開發人員指南中的 SELE CT

-- Get definition for the sales table. SELECT * FROM pg_table_def WHERE tablename = 'sales';
-- Find total sales on a given calendar date. SELECT sum(qtysold) FROM sales, date WHERE sales.dateid = date.dateid AND caldate = '2008-01-05';
-- Find top 10 buyers by quantity. SELECT firstname, lastname, total_quantity FROM (SELECT buyerid, sum(qtysold) total_quantity FROM sales GROUP BY buyerid ORDER BY total_quantity desc limit 10) Q, users WHERE Q.buyerid = userid ORDER BY Q.total_quantity desc;
-- Find events in the 99.9 percentile in terms of all time gross sales. SELECT eventname, total_price FROM (SELECT eventid, total_price, ntile(1000) over(order by total_price desc) as percentile FROM (SELECT eventid, sum(pricepaid) total_price FROM sales GROUP BY eventid)) Q, event E WHERE Q.eventid = E.eventid AND percentile = 1 ORDER BY total_price desc;