Help needed in SQL Query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Surendra

    Help needed in SQL Query

    I have a table that has fields GRP_CODE & END_DATE. For a given
    GRP_CODE and a given month of a year, there may be 1, 2 or 3 END_DATE
    values.
    For Example,
    GRP_CODE END_DATE
    AA 07/14/2003
    AA 07/28/2003
    BB 07/14/2003
    BB 07/28/2003
    AA 08/01/2003
    AA 08/15/2003
    AA 08/29/2003
    BB 08/01/2003
    BB 08/15/2003
    BB 08/29/2003
    ....

    I have to develop a query that has one input parameter, a date. The
    query should return either 0, 1, 2, or 3 based on the match with the
    END_DATE field.

    In the above example, here is what the query should return the
    following results for various input dates

    Input Date Query Output
    08/01/2003 1
    08/15/2003 2
    08/29/2003 3
    08/30/2003 0
    07/14/2003 1
    07/28/2003 2

    Can anybody help me with how the query can be written?

    Thanks in advance.
  • Alan Mills

    #2
    Re: Help needed in SQL Query


    "Surendra" <surendramuthye @yahoo.comwrote in message
    news:742a5eb5.0 308111952.eca63 db@posting.goog le.com...
    I have a table that has fields GRP_CODE & END_DATE. For a given
    GRP_CODE and a given month of a year, there may be 1, 2 or 3 END_DATE
    values.
    For Example,
    GRP_CODE END_DATE
    AA 07/14/2003
    AA 07/28/2003
    BB 07/14/2003
    BB 07/28/2003
    AA 08/01/2003
    AA 08/15/2003
    AA 08/29/2003
    BB 08/01/2003
    BB 08/15/2003
    BB 08/29/2003
    ...
    >
    I have to develop a query that has one input parameter, a date. The
    query should return either 0, 1, 2, or 3 based on the match with the
    END_DATE field.
    >
    In the above example, here is what the query should return the
    following results for various input dates
    >
    Input Date Query Output
    08/01/2003 1
    08/15/2003 2
    08/29/2003 3
    08/30/2003 0
    07/14/2003 1
    07/28/2003 2
    >
    Can anybody help me with how the query can be written?
    >
    Thanks in advance.
    Look up COUNT and GROUP BY in the manuals


    Comment

    • Surendra

      #3
      Re: Help needed in SQL Query

      I think I have not been clear in my requirements

      If there are 3 dates in a month, the indexes returned should be 1, 2,
      3 based on what date is passed in. So if the input date is 07/14/2003,
      since it is the first date in the month of July 2003, I should get the
      index value of 1. If I input the date as 08/01/2003, since it is the
      1st of the 3 date entries for August 2003, the query should return a
      value of 1. If I use 08/29/2003 as the input, the query should return
      an index of 3 as it is the third date in the month of August.




      "Alan Mills" <Alan.Mills@xse rvices.pants.fu jitsu.comwrote in message news:<bha7po$qq s$1@news.icl.se >...
      "Surendra" <surendramuthye @yahoo.comwrote in message
      news:742a5eb5.0 308111952.eca63 db@posting.goog le.com...
      I have a table that has fields GRP_CODE & END_DATE. For a given
      GRP_CODE and a given month of a year, there may be 1, 2 or 3 END_DATE
      values.
      For Example,
      GRP_CODE END_DATE
      AA 07/14/2003
      AA 07/28/2003
      BB 07/14/2003
      BB 07/28/2003
      AA 08/01/2003
      AA 08/15/2003
      AA 08/29/2003
      BB 08/01/2003
      BB 08/15/2003
      BB 08/29/2003
      ...

      I have to develop a query that has one input parameter, a date. The
      query should return either 0, 1, 2, or 3 based on the match with the
      END_DATE field.

      In the above example, here is what the query should return the
      following results for various input dates

      Input Date Query Output
      08/01/2003 1
      08/15/2003 2
      08/29/2003 3
      08/30/2003 0
      07/14/2003 1
      07/28/2003 2

      Can anybody help me with how the query can be written?

      Thanks in advance.
      >
      Look up COUNT and GROUP BY in the manuals

      Comment

      Working...