473,382 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Help with SQL statement, please

I've inherited a SQL statement that looks approximately like this:

SELECT Sum(tblA.A9A) As [1990],
Sum(tblA.A9A)/Sum(tblA.I9N) As [1990P],
Sum(tblA.A0A) As [2000],
Sum(tblA.A0A)/Sum(tblA.I9N) As [2000P]
FROM [geoB]
INNER JOIN tblA
ON [geoB].STFID = tblA.STFID;

1990,2000 refer to years and the number of years that appears in a
SQL varies. I'm uncomfortable with that Sum(tblA.I9N) which will be
repeated for each year in the SQL. Will the SQL automatically be
optimized so that sum is done only once? If not, how do I compute and
name it for use as an intermediate, but not make it one of the items selected?

thanks, --thelma
Jun 3 '06 #1
3 1313
Thelma Lubkin <th****@alpha2.csd.uwm.edu> wrote in
news:e5**********@uwm.edu:
I've inherited a SQL statement that looks approximately like
this:

SELECT Sum(tblA.A9A) As [1990],
Sum(tblA.A9A)/Sum(tblA.I9N) As [1990P],
Sum(tblA.A0A) As [2000],
Sum(tblA.A0A)/Sum(tblA.I9N) As [2000P]
FROM [geoB]
INNER JOIN tblA
ON [geoB].STFID = tblA.STFID;

1990,2000 refer to years and the number of years that appears
in a SQL varies. I'm uncomfortable with that Sum(tblA.I9N)
which will be repeated for each year in the SQL. Will the SQL
automatically be optimized so that sum is done only once? If
not, how do I compute and name it for use as an intermediate,
but not make it one of the items selected?

thanks, --thelma


You've also inherited a denormalized table which is a bigger
concern. I don't think thay you'll get much improvement as the
Jet engine appears to calculate all columns in a single pass
through the records.

--
Bob Quintal

PA is y I've altered my email address.
Jun 3 '06 #2
Bob Quintal <rq******@sympatico.ca> wrote:
: Thelma Lubkin <th****@alpha2.csd.uwm.edu> wrote in
: news:e5**********@uwm.edu:

:> I've inherited a SQL statement that looks approximately like
:> this:
:>
:> SELECT Sum(tblA.A9A) As [1990],
:> Sum(tblA.A9A)/Sum(tblA.I9N) As [1990P],
:> Sum(tblA.A0A) As [2000],
:> Sum(tblA.A0A)/Sum(tblA.I9N) As [2000P]
:> FROM [geoB]
:> INNER JOIN tblA
:> ON [geoB].STFID = tblA.STFID;
:> <snip>
:> I'm uncomfortable with that Sum(tblA.I9N)
:> which will be repeated for each year in the SQL.
:> <snip>

: You've also inherited a denormalized table which is a bigger
: concern. I don't think thay you'll get much improvement as the
: Jet engine appears to calculate all columns in a single pass
: through the records.

Thanks. The question was partly for my education, because I am
discussing a redesign of the tables with the person maintaining the
database. I'm not sure how far the redesign can go though, because
some of the tables used are from an outside source
--thelma
: --
: Bob Quintal

: PA is y I've altered my email address.
Jun 3 '06 #3
Thelma Lubkin <th****@alpha2.csd.uwm.edu> wrote in
news:e5**********@uwm.edu:
Bob Quintal <rq******@sympatico.ca> wrote:
: Thelma Lubkin <th****@alpha2.csd.uwm.edu> wrote in
: news:e5**********@uwm.edu:

:> I've inherited a SQL statement that looks approximately like
:> this:
:>
:> SELECT Sum(tblA.A9A) As [1990],
:> Sum(tblA.A9A)/Sum(tblA.I9N) As [1990P],
:> Sum(tblA.A0A) As [2000],
:> Sum(tblA.A0A)/Sum(tblA.I9N) As [2000P]
:> FROM [geoB]
:> INNER JOIN tblA
:> ON [geoB].STFID = tblA.STFID;
:> <snip>
:> I'm uncomfortable with that Sum(tblA.I9N)
:> which will be repeated for each year in the SQL.
:> <snip>

: You've also inherited a denormalized table which is a bigger
: concern. I don't think thay you'll get much improvement as
: the Jet engine appears to calculate all columns in a single
: pass through the records.

Thanks. The question was partly for my education,
because I am discussing a redesign of the tables with
the person maintaining the database. I'm not sure how
far the redesign can go though, because some of the
tables used are from an outside source
--thelma
: --
: Bob Quintal

: PA is y I've altered my email address.


I deal with a lot of data that I receive as Text files (some
..sdf, some delimited). I'll usually write a routine that imports
the data to a temp table, then runs queries to either update or
replace the data in properly normalized tables, as applicable.
If the amount of data is not large, one could simply use select
queries against the table to normalize the data for ease in
processing.

--
Bob Quintal

PA is y I've altered my email address.
Jun 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: duikboot | last post by:
Hi all, I'm trying to export a view tables from a Oracle database to a Mysql database. I create insert statements (they look alright), but it all goes wrong when I try to execute them in Mysql,...
46
by: Kingdom | last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off - type B I have 12 off etc. I'm using Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM Parts_Table") ...
2
by: Amanda | last post by:
From a guy in Microsoft newsgroups: | In *comp.databases.ibm-db2* there are always IBM guys | from the Toronto labs on line.Post with the | -for the love of god please help- | line...
5
by: Rated R1 | last post by:
I wrote this before in the NGs, so I am going to paste the responses that I got and see if someone can please help me. Email me and we can set something up as Id even be willing to pay for your...
5
by: Dan Nash | last post by:
Hi all, I've got a page with a user control on, added via VS. I'm trying to get to a property of the user control (or more precisely, a public var). Here's the code at the top of my aspx...
1
by: David | last post by:
Hi, I cannot get the following (MS Access) SQL statement working in my asp page, please can anyone help me ? Thanks :-) ------------------------------------------------ <% strQuery =...
22
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
5
by: wassimdaccache | last post by:
Dear Sirs; I'm trying to write SQL statement and it is not executing what I need. tables are: customers(customerID, customerName) ...
11
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG'...
2
by: lowradiation7 | last post by:
ok my brain is about to explode i do not get this at all can someone please help me out. Write a switch statement you may combine the less than and greater than into one statement. X is less...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.