|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SQL query help(Firebird)
hi
I want to manipulate over 3 fields (fromdate, todate and dep) wich belong to a table called 'let's say' X. fromdate - datetime type todate- datetime type dep - integer type Int - integer --------------------------------------------------- dep Int fromdate todate 100 2 01.01.2006 10:00 01.01.2006 20:00 200 2 01.01.2006 20:10 02.01.2006 10:30 100 2 02.01.2006 10:40 02.01.2006 11:00 100 3 01.01.2006 10:00 01.01.2006 20:00 200 3 01.01.2006 20:10 02.01.2006 10:30 100 3 02.01.2006 10:40 02.01.2006 11:00 So, my query has to select a given DEP (for example -100) but with latest TODATE field for a given Int field (for ex.- 2) More precisely - i don't know how to make relations between todate (and fromdate)fields with the given "int" and given (or group of) "dep" filed. The important latest 'todate'. thanks very much for the HELP!!! |
|
#2
|
|||
|
|||
|
Try this:
Code:
SELECT *
FROM x
WHERE INT = 2
AND dep = 100
AND todate = (SELECT MAX(todate)
FROM X x2
WHERE x2.int = x.int
AND x2.dep = x.int)
As a side note: "int" as the name for a column is not a very good idea as it leads to confusion (could be mistaken for a data type) and is actually a reserved word in some DBMS and last but not least does not tell you anything about the contents. Column names should be as descriptive as possible. |
|
#3
|
|||
|
|||
|
thanks Shammat
The real column title is not Int. I just put it because is short.A little more help....what if i want all rows from X, not only where INT = 2 AND dep = 100 |
|
#4
|
|||
|
|||
|
Quote:
Then leave out the condition on int and dep ![]() Code:
SELECT *
FROM x
WHERE todate = (SELECT MAX(todate)
FROM X x2
WHERE x2.int = x.int
AND x2.dep = x.int)
|
![]() |
| Viewing: Dev Shed Forums > Databases > Firebird SQL Development > SQL query help(Firebird) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|