On May 5, 6:57?pm, Jyoti Sahoo <jyoti…> wrote:> Thanks … you made may day :-)>> On Wed, May 5, 2010 at 6:42 PM, agarwalpra...@gmail.com <>>>>>> agarwalpra...@gmail.com> wrote:> > select from (select last prev SDATE by PRDID,DEPTID from t) where not> > SDATE like “”>> > On May 5, 2:37 am, Jyoti Sahoo <jyoti…> wrote:> > > Hi,>> > > Thanks for the replay…>> > > My requirement is:> > > I want 2nd last (last but one) values from the table group by> > PRDID,DEPTID> > > and SDATE <= “02-15-2010”.>> > > If there is only 1 record present in the table for the above condition> > then> > > it should return NULL rows instead of the same row that is available in> > the> > > table.>> > > The table that I mentioned below I want an out put like this:>> > > PRDID ? SDATE ? ? ? ? ? DEPTID> > > -------------------------------------------> > > ?1001 ? ?01-20-2010 ? ? ?E91> > > 1001 ? ?01-10-2010 ? ? ?E01>> > > To meet my requirement I tried this query:> > > q> unkey select first -2#PRDID,first -2#SDATE,first -2#DEPTID by> > > PRDID,DEPTID from t where SDATE <= “02-15-2010”>> > > and the response that I got is:> > > PRDID ? SDATE ? ? ? ? ? DEPTID> > > ------------------------------------------------> > > 1001 ? ?01-20-2010 ? ? ?E91> > > 1001 ? ?01-10-2010 ? ? ?E01> > > 1001 ? ?02-01-2010 ? ? ?E20>> > > As per my requirement I don’t want the last row (highlighted) as that is> > not> > > the 2nd last value (condition PRDID & DEPTID).>> > > I think this time I’m more clear in explaining the requirement>> > > Thanks,> > > Jyoti>> > > On Wed, May 5, 2010 at 6:13 AM, gabber <gabriel.rica…>> > wrote:> > > > Hello,> > > > It’s not exactly clear what you’re trying to do. ?But it looks like> > > > you want a result with duplicate columns filtered on a date from t?> > > > If that’s indeed what you’re looking for, your example result seems> > > > flawed, since the date you’re filtering on seems to match everything> > > > in your example table (<= “02-15-2010”, By the way is SDATE a string?> > > > Not sure why the date is enclosed in quotes in the select statement,> > > > but I assume SDATE is a string in table t).> > > > In any case, here’s an example that should work given my assumptions> > > > above.>> > > > q)t:(PRDID:6#1001;SDATE:>> > (“01-01-2010”;“01-20-2010”;“02-07-2010”;“01-10-2010”;“01-11-2010”;“02-01-20??10”);DEPTID:> > > > ((3#E91),(2#
E01),`E20))> > > > q)t> > > > PRDID SDATE ? ? ? ?DEPTID> > > > -------------------------> > > > 1001 ?“01-01-2010” E91> > > > 1001 ?“01-20-2010” E91> > > > 1001 ?“02-07-2010” E91> > > > 1001 ?“01-10-2010” E01> > > > 1001 ?“01-11-2010” E01> > > > 1001 ?“02-01-2010” E20> > > > q)select PRDID,DEPTID,PRDID,SDATE,DEPTID from t where> > > > (“D”$SDATE)<=2010.01.15> > > > PRDID DEPTID PRDID1 SDATE ? ? ? ?DEPTID1> > > > ----------------------------------------> > > > 1001 ?E91 ? ?1001 ? “01-01-2010” E91> > > > 1001 ?E01 ? ?1001 ? “01-10-2010” E01> > > > 1001 ?E01 ? ?1001 ? “01-11-2010” E01>> > > > On Apr 30, 3:58 am, Jyoti <jyoti…> wrote:> > > > > Hi,>> > > > > Please take look at the below requirement and let me know the> > > > > solution…>> > > > > table t,>> > > > > PRDID ? SDATE ? ? ? ? ? DEPTID> > > > > -------------------------------------> > > > > 1001 ? ?01-01-2010 ? ? ?E91> > > > > 1001 ? ?01-20-2010 ? ? ?E91> > > > > 1001 ? ?02-07-2010 ? ? ?E91> > > > > 1001 ? ?01-10-2010 ? ? ?E01> > > > > 1001 ? ?01-11-2010 ? ? ?E01> > > > > 1001 ? ?02-01-2010 ? ? ?E20>> > > > > unkey select first -2#PRDID,first -2#SDATE,first -2#DEPTID by> > > > > PRDID,DEPTID from t where SDATE <= “02-15-2010”>> > > > > I’m getting:>> > > > > PRDID ? DEPTID ?PRDID ? SDATE ? ? ? ? ? DEPTID> > > > > ------------------------------------------------> > > > > 1001 ? ?E91 ? ? 1001 ? ?01-20-2010 ? ? ?E91> > > > > 1001 ? ?E01 ? ? 1001 ? ?01-10-2010 ? ? ?E01> > > > > 1001 ? ?E20 ? ? 1001 ? ?02-01-2010 ? ? ?E20>> > > > > But my requirment is to get rows like this:>> > > > > PRDID ? DEPTID ?PRDID ? SDATE ? ? ? ? ? DEPTID> > > > > --------------------------------------------------------------------> > > > > 1001 ? ?E91 ? ? 1001 ? ?01-20-2010 ? ? ?E91> > > > > 1001 ? ?E01 ? ? 1001 ? ?01-10-2010 ? ? ?E01>> > > > > Thanks>> > > > > –> > > > > You received this message because you are subscribed to the Google> > Groups> > > > “Kdb+ Personal Developers” group.> > > > > To post to this group, send email to> > personal-kdbplus@googlegroups.com.> > > > > To unsubscribe from this group, send email to> > > > personal-kdbplus+unsubscribe@googlegroups.com> > > > > > .> > > > > For more options, visit this group athttp://> > > > groups.google.com/group/personal-kdbplus?hl=en.>> > > > –> > > > You received this message because you are subscribed to the Google> > Groups> > > > “Kdb+ Personal Developers” group.> > > > To post to this group, send email to personal-kdbplus@googlegroups.com> > .> > > > To unsubscribe from this group, send email to> > > > personal-kdbplus+unsubscribe@googlegroups.com> > > > > > .> > > > For more options, visit this group at> > > >http://groups.google.com/group/personal-kdbplus?hl=en.>> > > –> > > Thanks,> > > Jyoti!!!>> > > –> > >
Submitted via Google Groups</jyoti…></gabriel.rica…></jyoti…></jyoti…>