views:

807

answers:

4

My SQL skills are rather limited and since I find myself working with a DB (Oracle) a lot lately I would like to get beyond the basic select statements.

I want to write queries that do things like get data from multiple tables, sum quantities, compare dates, group, filter etc.

What sites can you recommend for getting SQL reporting skills to a more advanced level?

+2  A: 

I know this isn't online, but it fits your bill to a T:

I would recommend picking up a copy of Anthony Mollinaro's SQL Cookbook. It describes how to do lots of complicated things that go beyond the basic SELECT FROM WHERE . In a prev. life, when doing lots of queries for a prev. job, that book was my life saver and people borrowed that book a lot. It has lots of very clear examples, and they range from the simple (How to retrieve a subset of rows on a table) to the complex (using window functions to generate histograms).

It's not free, but the book will pay for itself rather quickly, and I imagine would answer most of the questions you would have. NOTE: I have no connection with O'Reilly or Mr. Mollinaro, I simply think this book is awesome and ridiculously helpful.

sheepsimulator
+2  A: 

Read chapter 20, 21 and 22 of the Oracle data ware house guide: http://download.oracle.com/docs/cd/B28359_01/server.111/b28313/toc.htm . It's about grouping, analytics and the model clause.

tuinstoel
A: 

W3 Schools SQL Tutorial is a good place to start. It gives some examples of the different types of joins and details a lot of the functions (i.e. sum, count, avg). I really had to build a foundation in SQL before understanding complex queries.

scottm
+4  A: 

Pick up Joe Celcko's SQL For Smarties. That's one of the definitive take-your-sql-to-the-next-level books. Otherwise, just keep writing queries.

Make sure you understand joins. Since the beginning of time, my SQL methodology has always been row-count driven - In other words, as I write a complicated query, I'm always #1 making sure it returns the correct number of rows. If your rowcount is correct, then your sums/groups/aggregates will all be correct. And they are VERY easy to mess up.

Make sure you understand the data. Make sure you understand keys and uniqueness so that you can enforce your joins.

You can also read asktom.oracle.com for a lot of really cool SQL trickery. Laurent Schneider is also very cutting-edge sql-wise. I wouldn't be half the DBA/Developer I am today had I not set asktom as my home page for the last 5-6 years.

Finally, make sure you understand set based operations. Think of the result set as a whole, not just a collection of rows. It'll click as you do it. This relates back to the row-count-driven methodology.

Neil Kodner