With a little time and practice you'll be writing advanced queries like a pro.
A strong foundation
It's possible to grasp the basic use of object-relational mapping (ORM) but still feel you lack the basics of how databases work. To get a solid footing on understanding relational databases you can try one of these free courses:
If you feel pretty confident in your understanding of how databases work but just need the basics of SQL explained, one of these step by step tutorials may be just what you need.
Study by yourself - SQL — An 11 chapter course that starts with the basics of data modeling and progresses to aggregate functions and advanced queries.
Learn the Hard Way - SQL — An SQL version of their familiar lessons progressing from beginner to advanced concepts. It's still in Alpha release but has a lot of good content already.
Resources to practice
The best way to get more confident with SQL is through practice. The key is to use tools that refine your skills and practice consistently:
SQLZoo.net — Provides practice and quizzes to boost your skills
SQLTeaching — If you like learn by example introductions to new languages this is the resource for you.
SQLCourse — Interactive online sql training
PGExercises — For those who learn by doing, try jumping right in with these exercises
SQLFiddle — Completely free form SQL practice. Build your own schema, run queries, or practice on a sample fiddle. If you like JSFiddle this is a similar tool.
Testing your skills
With a little practice under your belt you may want to test your skills at SQL Quiz. SQL Quiz presents random questions and keeps track of your results. The results provide links to learn more about the questions you missed.
As your confidence grows try your hand at a little competition with schemaverse, too.
If you are enjoying the deep dive into SQL and how databases work, take a lunch hour or two and enjoy a few conference talks. These are a great way to solidify learning and discover best practices.