What type of DB are your using, SQLServer 7/2000?
Main Topics
Browse All TopicsHi
I have two tables:
Question Response
---------- -----------
curr_id curr_id
prev_id score
The question table holds a list of questions each with its own unique ID. The questions can change over time and when a change happens a new question is loaded into the question table with a new curr_id, The curr_id of the old question that the new one changed from is not removed from the table and to signify that the new question stemed from the old the old question Curr_id is placed into the new questions prev_id field. The response table holds numeric responses to the questions.
Some possible values in these tables may be:
curr_id prev_id Qstn_id Score
1 - 1 1
2 1 2 1
3 - 3 1
4 - 4 1
5 3 5 1
6 - 6 1
7 5 7 1
I want to find some SQL that will give a sum of all the scores for each question (excluding the old ones) that inclues the values of all previous versions of the question. So for example using the values above question 7 should receive a sumed up score of 3 (1 from id=7 1 from id=5 and 1 from id=3). I need to do this with straight SQL that can be used on multiple DBs. I've been struggling with this for a few days now with out any success. Does any one know how to do this or wether its possible.
Thanks
David
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
HI
There is no max number for question revesions, and i need it in standard SQL because I will be using that sql to pull the data from a star schema and into an Esspase cube. I can do this by using a standard programing language like Java to create a flat file containing the data but I wanted to try and do it using SQL. I'm not sure it can be done either, but I thought there might be something I'm missing.
The DB I'm using is acctually oracle 9i.
Thanks
Dave
Dave
>> I'm not sure it can be done either, but I thought there might be something I'm missing
As i wrote before, if you don't have an upper limit for revisions, I am sure it cannot be done in standard SQL.
So, the answer for your question is "Can't be done".
As for workarounds - your idea of using programming language sounds quite reasonable for the case.
RaisinJ's idea is also possible - than again it won't be Standard SQL, but will use Oracle specific functions.
Another option is to modify your DB so it will include a straight connection from a revision to the question ID. An idea for such a design that will not suffer from duplication of data is to have one table of QuestionIDs that will have a fixed number for each ID, and another table that will have the reviosion, something like:
QuestionID
Revision
Score
so instead of having a fixed number for each revision the PK of a revision will be the questionID + revision number. I think it's more flexible data-structure, but am not sure if changing your database schema is acceptable for you.
Good luck
Zvika
I don't see why the question should be closed...
NHBFighter said: "I guess the correct answer is that it can't be done using standard SQL."
this is exactly the answer I gave him in the first comment on this page
(>> Do you have any maximum number of possible "revisions" for a question? If not, Standard SQL (ANSI) can not give you what you need.)
and again on the last comment on this page
(>> As i wrote before, if you don't have an upper limit for revisions, I am sure it cannot be done in standard SQL. So, the answer for your question is "Can't be done".)
I think I gave him a full answer, no?
Business Accounts
Answer for Membership
by: ZvikaPosted on 2004-10-10 at 02:14:34ID: 12269566
Do you have any maximum number of possible "revisions" for a question?
If not, Standard SQL (ANSI) can not give you what you need. Maybe T-QSL or something else (depends on your database type) can do such actions.
if you do have a maximum number, maybe I can write something for you.
Zvika