
3. Now try the example queries. For more information, go to SELECT in the Amazon Redshift Developer
Guide.
-- 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;
4. You can optionally go the Amazon Redshift console to review the queries you executed.The Queries
tab shows a list of queries that you executed over a time period you specify. By default, the console
displays queries that have executed in the last 24 hours, including currently executing queries.
• Access the Amazon Redshift console at https://console.aws.amazon.com/redshift.
• In the cluster list in the right pane, click examplecluster.
• Click the Queries tab.
The console displays list of queries you executed as shown in the example below.
• In the list of queries, select a query to find more information about it.
API Version 2012-12-01
16
Amazon Redshift Getting Started Guide
Step 5: Load Sample Data from Amazon S3
Comentários a estes Manuais