Skip to main content
gamedev.net
🔒 Locked

SQL question

Started by johnnyBravo Nov 19, 2003 at 9:33 AM 6 replies 1.1k views
Original Post
johnnyBravo
johnnyBravo
im in college and i have a question asking me to "display a bunch of data for the year". Then at the end of this it asks me to display the "total sum of some numbers" from the same table. This is to be one query. I don't see how you can output a table and then display a calculation at the bottom. What can i do? Thanks, [edited by - johnnyBravo on November 19, 2003 10:34:41 AM]
JY
JY
Use the SUM aggregate, ie:

SELECT SUM(whatever) FROM wherever;



"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
Nik02
Nik02
The sum needs an own table/result set, AFAIK, since it's not a same type of record as the data itself.

-Nik

EDIT:
So strictly, again AFAIK, it can't be in same query, unless you include the sum in every record as it's own column. However, why don't you use two different queries, the data query and one that JY suggests?

[edited by - Nik02 on November 19, 2003 10:46:26 AM]
Niko Suni
johnnyBravo
johnnyBravo
Thanks,

but about not using two queries....
Maybe i read this wrong but i don't think so.
this is the question.
quote:

List all the car services performed this calender year, showing the date, cost, car make and model and customer name. Also display a total of the service costs at the bottom - this is one query, not two.



Maybe my teacher is just stupid



[edited by - johnnyBravo on November 19, 2003 10:56:45 AM]
mrbastard
mrbastard
why not ask your teacher? if he won''t explain, then yes he''s stupid. If you don''t ask, then you are

worth thinking about: "bottom" is to do with layout, not the query - for instance in access (hateful program that it is) you could have the running total column in each record in the query BUT have that column hidden in the main page, and then a control in the footer that shows max(total). One query, but layed out the way you want.

[size="1"]
johnnyBravo
johnnyBravo
I would, just that this is part of an assignment and i dont want to rush in class 2mo to finish, tryin to do it all 2ni or morning....

i cant seem to find anything on layout, but ill have a look at creating views....came up after searching for layout
mrbastard
mrbastard
Just to be clear, layout isn''t a key word it''s just the word I picked. In the dbms I use, sql queries are used to generate record sets from a databse. I then use the dbms form editor to lay out how the user will see the data the query collected. I was just trying to point out that whether the total is at the bottom or on every row doesn''t have to have anything to do with sql, its how your interface shows it.

Most interfaces will show a total for every row, but that doesn''t mean you have to. Make sense?

Of course in the strict database sense of the word row (to mean record) you will have a running total on every row if you do it as one query.

What dbms software are you using?
[size="1"]
johnnyBravo
johnnyBravo
ibm db2,

Yes i see what you mean.

Ill ask my teacher tomorrow(or today to be technical)

from what you''ve all being telling i believe my teacher is wrong, which isnt new he seems to be wrong quite a bit, just getting him to admit it is the hard part!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.