Einzelnen Beitrag anzeigen

omata

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

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

  Alt 29. Feb 2008, 00:44
Vielleicht so...

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 wp.thedate = (SELECT MAX(thedate)
                    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 wp.thedate = (SELECT MAX(thedate)
                    FROM wsprogress
                    WHERE wsid = wp.wsid)
Gruss
Thorsten
  Mit Zitat antworten Zitat