select top 3 - for each id

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello,

I have table with nubers of 'dates' for each id,
the 'dates' are not the same from id to id.
i want to show the top/last 'dates' for each id.
how ?

thanks
 
×©×œ×•× ×™×¨×™×‘ החביב,

Try this type of a query

SELECT M1.ID, M1.DateFieldName
FROM TableName AS M1
WHERE M1.DateFieldName In (SELECT Top 3 M2.DateFieldName
FROM TableName as M2
WHERE M2.ID =M1.ID
ORDER BY M2.DateFieldName Desc)
 
עופר ×©×œ×•× ×•×ª×•×“×” לעזרתך,
יש לי טבלה ×חת בלבד
ובפקודה שנתת לי ×תה משתמש בשתי טבל×ות
×ו ש×× ×™ ×œ× ×ž×‘×™×Ÿ.
×”×× ×ª×•×›×œ להסביר
 
למעשה מדובר בטבלה ×חת
תחליף ×ת TableName ×‘×©× ×”×˜×‘×œ×” שלך, ותנסה ×¢× ×©×ž×•×ª השדות הנכוני×

ID - תחליף ×‘×©× ×”×©×“×” שלך
DateFieldName - צריך להיות ×©× ×©×“×” ת×ריך

×× ×תה צריך עזרה תשלח ×ת ×©× ×”×˜×‘×œ×” והשדות.
 
עופר תודה,
עשיתי ×יך ש×מרת ויצ×ו לי שלושה ערכי×:
שלוש זהויות בעלי הת×ריך הגבוה ביותר.

למעשה זוהי ש×ילתה ×•×œ× ×˜×‘×œ×”

×”×ž×©×ª× ×™× ×”×:
ID = zihuy
DateFieldName=month

להלן המשפט שכתבתי:

SELECT Qhoofshatleyda_avgshati2.zihuy, Qhoofshatleyda_avgshati2.month
FROM Qhoofshatleyda_avgshati2

WHERE (((Qhoofshatleyda_avgshati2.month) In (SELECT Top 3
Qhoofshatleyda_avgshati2.month
FROM Qhoofshatleyda_avgshati2
WHERE Qhoofshatleyda_avgshati2.zihuy =Qhoofshatleyda_avgshati2.zihuy
ORDER BY Qhoofshatleyda_avgshati2.month Desc)));
 
Try

SELECT QA1.zihuy, QA1.month
FROM Qhoofshatleyda_avgshati2 As QA1
WHERE QA1.month In (SELECT Top 3 QA2.month
FROM Qhoofshatleyda_avgshati2 As QA2
WHERE QA2.zihuy =QA1.zihuy
ORDER BY QA2.month Desc)
 
עופר תודה רבה,

הש×ילתה, ×ומנ×, עובדת הרבה זמן,
×בל נותנת ×ת התוצ×ות הרצויות.

בברכה,

יריב
 
My Hebrew is not good enough to know if this is resolved, but if subqueries
are a new concept, this recent article might help:
Subquery basics - What subqueries are; 5 examples of why you want them
at:
http://allenbrowne.com/subquery-01.html

Particularly the "Top N Records per group" example might help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top