0

When I run this query I get:

SELECT DISTINCT r2.ApplicationBK,
                max(r2.DatumApplication) maxdatum,
                p.Name
FROM FCT_Recruitment r2,
     DIM_WervingsProject wp,
     DIM_Persoon p
WHERE r2.WervingsProjectID = wp.WervingsProjectID
  AND r2.PersoonID=p.PersoonID
GROUP BY ApplicationBK,
         p.name

The names are standing in TALBLE DIM_PERSOON P
The "ApplicationBK" are standing in DIM_Wervingsproject
and all the dates (DatumAppliocation) are standing in FCT_Recruitment

BK  -  Date - Name 
012    20-03-1999  - name1 
023    21-03-1999  - name1 
033    22-03-1999  - name1 
112    20-03-1990  - name2 
123    20-03-1999  - name2 
133    20-03-1990  - name2

But i need the highest date for each name.. So each name may only stand one time in the 'name-column' with the corresponding id (ApplicationBK) and date. I don't need to rest.

When this didn't work I tried something else...

SELECT WervingsprojectBK,
       r.ApplicationBK,
       p.Name,
       count(*) number,upper(r.StatusWP) status,
                       upper(r.StatusApplication)statusdetail,
                       r.DateApplication 
FROM FCT_Recruitment AS r,
     DIM_WervingsProject wp,
     DIM_Persoon p
INNER JOIN
  (SELECT DISTINCT r2.ApplicationeBK,
                   max(r2.DateApplication) maxdatum
   FROM FCT_Recruitment r2,
        DIM_WervingsProject wp,
        DIM_Persoon p
   WHERE r2.WervingsProjectID=wp.WervingsProjectID
     AND r2.PersoonID=p.PersoonID
   GROUP BY ApplicationBK) AS r2 ON (r.ApplicationBK=r2.ApplicationBK
                                     AND r.DateApplication=r2.maxdatum)
GROUP BY WervingsprojectBK,
         r.ApplicationBK,
         p.Naam,
         r.StatusApplication,
         r.StatusWP
ORDER BY 5

but then i get these errors..:

Msg 4104, Level 16, State 1, Line 3 The multi-part identifier "r.ApplicationBK" could not be bound. Msg 4104, Level 16, State 1, Line 3 The multi-part identifier "r.DateApplication" could not be bound.

Can you please help this newby.. Thanks.

4

2 回答 2

0

试试这个:

select 
  r2.ApplicationBK, 
  r22.maxdatum, 
  p.Name
from FCT_Recruitment r2
INNER JOIN
(
  SELECT WervingsProjectID, max(r2.DatumApplication) maxdatum
  FROM FCT_Recruitment
  GROUP BY WervingsProjectID
) AS r22  ON r2.WervingsProjectID = r22.WervingsProjectID
         AND r2.DatumApplication  = r22.maxdatum
INNER JOIN DIM_WervingsProject AS wp ON r2.WervingsProjectID = wp.WervingsProjectID
INNER JOIN DIM_Persoon         AS p  ON r2.PersoonID         = p.PersoonID;
于 2013-03-28T10:09:14.070 回答
0

尝试这个。并更改列名:

SELECT max(r.AllDate),r.ProjectID,p.name 
FROM FCT_Recruitment r,DIM_Wervingsproject pr, DIM_PERSOON p 
where p.PID=r.PID and r.ProjectId=pr.ProjectID 
group by r.PID;
于 2013-03-28T11:17:43.000 回答