What are you trying to do with that SQL, anyway?
Delbert the Rooster

What are you trying to do with that SQL, anyway?

I worked as a DBA/Developer on a utility company data conversion project. A very junior developer had been given a task of writing a query to sum up all the utility billing line items by customer. The purpose was to be able to compare before and after and make sure nothing got screwed up during the conversion. The developer had been given a query of how to join everything so that they would be able to write these kinds of queries.

The developer came to me and explained that the query was taking forever, what to do?

His query:

Select c.customer_id, sum(t.amount), from customer c, transaction t, customer_address ca, customer_type ct, meter_type m where c.customer_id = t.customer_id and c.customer_id = ca.customer_id and ca.address_type = 'B' and c.customer_type_id = ct.customer_type_id and c.meter_type_id = m.meter_type_id group by c.customer_id;

First I explained to him that what he was trying to do was probably going to take a long time regardless, but......

select customer_id, sum(amount) from transaction group by customer_id;

He was joining 5 tables when he only needed to hit one table. Why was he hitting 5 tables? Well, that's the training he had received. Use this base query and you will be able to get everything you need from it.

If you have junior developers who don't know what they are doing with SQL, you have to take the time to teach them. Teach them to understand the data, understand the relationships between the tables. Instead of giving them a generic block of code that you can use to query anything, teach them about the data, and teach them to write the one query that will be the best way of extracting the data they need for the task at hand.

If your teammates don't know what you know, take the time to teach them. If your teammates know more than you know, take the time to learn from them. That's how to build relationships and teams that work together.

Rules for living a happy life. Do unto others. Love your neighbor. Always be humble (except on resumes and job interviews).











Like
Reply

Teach your children well....

Like
Reply

It's the little things, and nurturing the junior developers is key to building a great team.

To view or add a comment, sign in

More articles by James Strater

  • Oracle Performance without OEM

    I had a situation where a client facing process was processing 36 rows per hour. They needed to process 3.

    1 Comment
  • How do you eat an elephant?

    For many years I've seen people write SQL that will do what is being asked. But they aren't taking into consideration…

Others also viewed

Explore content categories