MySQL Forums
Forum List  »  Newbie

Re: SUM problem.
Posted by: Chris Preston
Date: March 22, 2009 05:01PM

Actually,

I solved your problem the first time and tested it and it worked. You only had to put in the right column and table names.

What you did was far more complex than an accurate single SQL query solution is and is called "hacking" - something that used to be frowned upon 20 or so years back, but seems to be all the rage today.

Ergo:

#1 if something seems too complex to you, it's probably the case that further reading and self-education are called for

#2 temporary tables are only needed in cases such as a data model that won't support a direct query or can't do so efficiently, the need to create multiple different results sets for reference (e.g. summary aggregate tables in a data warehouse) from the same intermediate result such that the temporary table is re-used, the optimizer can't handle the query (Postgres comes to mind primarily in this scenario)

#4 "Simple" in SQL doesn't mean "top down iterative" - you prefer an iterative solution because that is how your mind is able to grasp the problem more easily - SQL is *iterative* in nature, but the language does not *look* iterative. The solution I gave you was highly iterative in nature, but it executed from the inside out rather than top down - that's the big difference with SQL - if you are to master it some day, you must learn to understand programming semantics that are not top down. For a different language that requires a similar way of thinking, look into the Lisp programming language. Learn to write Lisp and you'll have a far easier time understand SQL. The reverse is not necessarily true.

Ah well, just the same, it's good you read some stuff and solved the problem a different way on your own. Your result is *a* solution, more complex and harder to maintain, but a solution nonetheless and that oftentimes is all that matters to many folks these days ... alas.


--chris

Options: ReplyQuote


Subject
Written By
Posted
March 12, 2009 03:29AM
March 12, 2009 09:52AM
March 13, 2009 07:10PM
March 13, 2009 11:10PM
March 14, 2009 04:01PM
March 14, 2009 06:40PM
March 15, 2009 07:54AM
March 15, 2009 10:41AM
March 15, 2009 10:35PM
March 16, 2009 09:33AM
March 16, 2009 09:52AM
March 16, 2009 02:46PM
March 16, 2009 04:15PM
March 17, 2009 02:11PM
March 17, 2009 05:03PM
March 17, 2009 06:31PM
March 17, 2009 10:17PM
March 18, 2009 06:03AM
March 15, 2009 05:41PM
March 15, 2009 07:14PM
March 16, 2009 08:34AM
March 18, 2009 12:52AM
March 21, 2009 05:58AM
March 21, 2009 11:13AM
Re: SUM problem.
March 22, 2009 05:01PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.