Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old May 2nd, 2008, 05:15 AM
felipevianna felipevianna is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Location: Rome
Posts: 3 felipevianna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m 5 sec
Reputation Power: 0
Unhappy Help with a oracle select query

hello everybody!

I'm in a trouble.... can anybody help me... ?

well I have one log DATABASE table like this:

tablename: logs

Quote:
+-------+-----+------------+----------------------+
| office | user | event | date |
+-------+-----+------------+----------------------+
| seller | mike | question | 12/12/2007 10:12 |
| seller | mike | answer | 12/12/2007 10:14 |
| seller | mike | question | 12/12/2007 10:25 |
| seller | mike | answer | 12/12/2007 10:30 |
| seller | tom | question | 12/12/2007 10:33 |
| seller | tom | answer | 12/12/2007 10:34 |
| seller | mike | question | 12/12/2007 10:45 |
| seller | mike | answer | 12/12/2007 10:50 |
+-------+-----+------------+----------------------+


I need to extract the time between questions and the respective answers
Because we have others db fields (here I wrote just a simple example) I' ll need to use the date with a parameter
I'll need to take the question and the next 'answer' using the date , I think! and calculate the time between the registers...

I wrote a SELECT like this:

SELECT a.office, a.user, a.event, b.event, a.date, b.date
FROM logs a, logs b
WHERE a.office = b.office AND a.user = b.user AND ??????

well... here is my problem
I cant link the respective rows

+-------+-----+------------+----------------------+
| office | user | event | date |
+-------+-----+------------+----------------------+
| seller | mike | question | 12/12/2007 10:12 |
| seller | mike | answer | 12/12/2007 10:14 |

| seller | mike | question | 12/12/2007 10:25 |
| seller | mike | answer | 12/12/2007 10:30 |
| seller | tom | question | 12/12/2007 10:33 |
| seller | tom | answer | 12/12/2007 10:34 |

| seller | mike | question | 12/12/2007 10:45 |
| seller | mike | answer | 12/12/2007 10:50 |
+-------+-----+------------+----------------------+


the query replies this:

| seller | mike | question | 12/12/2007 10:12 | | seller | mike | answer | 12/12/2007 10:14 |
| seller | mike | question | 12/12/2007 10:12 | | seller | mike | answer | 12/12/2007 10:30 |
| seller | mike | question | 12/12/2007 10:12 | | seller | tom | answer | 12/12/2007 10:34 |
| seller | mike | question | 12/12/2007 10:12 | | seller | mike | answer | 12/12/2007 10:50 |
and
| seller | mike | question | 12/12/2007 10:25 || seller | mike | answer | 12/12/2007 10:14 |
| seller | mike | question | 12/12/2007 10:25 || seller | mike | answer | 12/12/2007 10:30 |
| seller | mike | question | 12/12/2007 10:25 || seller | tom | answer | 12/12/2007 10:34 |
| seller | mike | question | 12/12/2007 10:25 || seller | mike | answer | 12/12/2007 10:50 |
and...

but I need just:
| seller | mike | question | 12/12/2007 10:12 | | seller | mike | answer | 12/12/2007 10:14 |
| seller | mike | question | 12/12/2007 10:25 || seller | mike | answer | 12/12/2007 10:30 |
...

waiting and thanks ....

Reply With Quote
  #2  
Old May 2nd, 2008, 07:09 AM
Ebot's Avatar
Ebot Ebot is offline
Meatball Surgeon
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Elbow deep in code
Posts: 1,163 Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 21605 Folding Title: Starter FolderFolding Points: 21605 Folding Title: Starter Folder
Time spent in forums: 1 Week 4 Days 3 h 34 m 39 sec
Reputation Power: 684
Well first you need to fix your table. You need a primary key and a foriegn key to get this working properly.

As for figuring out the difference in time, just do question_date - answer_date. It will give you a number that represents the difference in days
__________________
The liver is evil and must be punished!

Reply With Quote
  #3  
Old May 2nd, 2008, 07:35 AM
felipevianna felipevianna is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Location: Rome
Posts: 3 felipevianna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m 5 sec
Reputation Power: 0
Quote:
Originally Posted by Ebot
Well first you need to fix your table. You need a primary key and a foriegn key to get this working properly.

As for figuring out the difference in time, just do question_date - answer_date. It will give you a number that represents the difference in days


ok!
step-by-step I'll need first the reply:
Quote:
| seller | mike | question | 12/12/2007 10:12 | | seller | mike | answer | 12/12/2007 10:14 |
| seller | mike | question | 12/12/2007 10:25 || seller | mike | answer | 12/12/2007 10:30 |
...



how can I do this reply without moddify the table, just using SELECTs, JOINs and UNIONs and .... ???

thnx

Reply With Quote
  #4  
Old May 2nd, 2008, 08:35 AM
Ebot's Avatar
Ebot Ebot is offline
Meatball Surgeon
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Elbow deep in code
Posts: 1,163 Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 21605 Folding Title: Starter FolderFolding Points: 21605 Folding Title: Starter Folder
Time spent in forums: 1 Week 4 Days 3 h 34 m 39 sec
Reputation Power: 684
You going to have to modify your table to fix this issue. Currently, you have no way of mapping your answer row to your question row, thats why you need to add the PK and FK.

Reply With Quote
  #5  
Old May 2nd, 2008, 09:36 AM
felipevianna felipevianna is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Location: Rome
Posts: 3 felipevianna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m 5 sec
Reputation Power: 0
Quote:
Originally Posted by Ebot
You going to have to modify your table to fix this issue. Currently, you have no way of mapping your answer row to your question row, thats why you need to add the PK and FK.


how can I do this?





----
I add to the query : answer_day > question_day

and the reply was:

Quote:
the query replies this:

| seller | mike | question | 12/12/2007 10:12 | | seller | mike | answer | 12/12/2007 10:14 |
| seller | mike | question | 12/12/2007 10:12 | | seller | mike | answer | 12/12/2007 10:30 |
| seller | mike | question | 12/12/2007 10:12 | | seller | tom | answer | 12/12/2007 10:34 |
| seller | mike | question | 12/12/2007 10:12 | | seller | mike | answer | 12/12/2007 10:50 |
and
| seller | mike | question | 12/12/2007 10:25 || seller | mike | answer | 12/12/2007 10:30 |
| seller | mike | question | 12/12/2007 10:25 || seller | tom | answer | 12/12/2007 10:34 |
| seller | mike | question | 12/12/2007 10:25 || seller | mike | answer | 12/12/2007 10:50 |
and...


if could I ignore the others repeated questions rows the reply would like this ...

Quote:

| seller | mike | question | 12/12/2007 10:12 | | seller | mike | answer | 12/12/2007 10:14 |
| seller | mike | question | 12/12/2007 10:25 || seller | mike | answer | 12/12/2007 10:30 |
...





ok! more... I can use the date like a primary key because is unique.... and the fk ... ?


can I discard repeated answers using the date question?

Reply With Quote
  #6  
Old May 2nd, 2008, 09:52 AM
Ebot's Avatar
Ebot Ebot is offline
Meatball Surgeon
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Elbow deep in code
Posts: 1,163 Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)Ebot User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 21605 Folding Title: Starter FolderFolding Points: 21605 Folding Title: Starter Folder
Time spent in forums: 1 Week 4 Days 3 h 34 m 39 sec
Reputation Power: 684
Well, can there be multiple answers to each question? if so, i would create a second table (lets call it Answers) it can be formatted just like you current table. you will then need to add another numeric column (lets call it answers2questions) that will be used to link the table to the questions table.

now on the questions table, you will also need to add a new numeric column to use as your primary key (say, answers_id). You will then have to give each row its own unique number. The number assigned will then have to go into the answers2questions column.

Overall, you may want to read up on your DB design, and it would be really good to read up on 3rd level of normalization.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Help with a oracle select query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway