Einzelnen Beitrag anzeigen

omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#10

Re: je ein Eintrag mit dem höchsten Datum (Group By ?)

  Alt 29. Feb 2008, 21:44
Ok, hier ein neuer Versuch...

SQL-Code:
SELECT 'aAS typ, wp.wsid, wp.thedate, wp.thevalue,
       s.wsid AS ws_id, p.projectid AS project_id
FROM wsprogress wp
INNER JOIN workstep s
  ON wp.wsid = s.wsid
INNER JOIN project p
  ON s.projectid = p.projectid
WHERE p.id = 110
  AND wp.thedate <= :bis_datum
  AND CAST(wp.thedate + wp.thetime AS TIMESTAMP)
      = (SELECT MAX(CAST( thedate + thetime AS TIMESTAMP))
         FROM wsprogress
         WHERE wsid = wp.wsid
           AND thedate <= :bis_datum)

UNION

SELECT 'bAS typ, wp.wsid, wp.thedate, wp.thevalue,
       s.wsid AS ws_id, p.projectid AS project_id
FROM wsprogress wp
INNER JOIN workstep s
  ON wp.wsid = s.wsid
INNER JOIN project p
  ON s.projectid = p.projectid
WHERE p.id = 110
  AND CAST(wp.thedate + wp.thetime AS TIMESTAMP)
      = (SELECT MAX(CAST( thedate + thetime AS TIMESTAMP))
         FROM wsprogress
         WHERE wsid = wp.wsid)
Gruss
Thorsten
  Mit Zitat antworten Zitat