Results 1 to 5 of 5

Thread: Help-me

  1. #1
    Join Date
    Jul 2003
    Posts
    3

    Exclamation Unanswered: Help-me

    Hi all,
    I have this problem... can someone help-me whith this sql?

    SELECT

    COUNT(*) AS STUDANTS,
    MONTH(TS_INC) AS MONTH,
    YEAR(TS_INC) AS YEAR

    FROM

    DB2TBW.ISCR_TREN_ATDV

    GROUP BY MONTH(TS_INC)

    its generate this problem.....

    IBM][CLI Driver][DB2] SQL0104N An unexpected token "(" was found following "". Expected tokens may include: "FOR WITH ORDER UNION EXCEPT QUERYNO OPTIMIZE ". SQLSTATE=42601

    tanks all

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    I believe you need to GROUP BY both columns selected (except the COUNT(*)).

    You might need to refer to the column(s) in the GROUP BY clause as MONTH and YEAR since you re-named them that.

  3. #3
    Join Date
    Mar 2003
    Location
    Singapore
    Posts
    200
    I think there is some problem with date and group by.If u also use the groupp by year clause,it will work

    select count(*) as students, month(join_date) as month,year(join_date) as year from students group by month(join_date) , year(join_date)

    --will work fine

    If we remove one of the group by parameter it won't work,but will work if we don't call that field.

    select count(*) as students, month(join_date) as month,year(join_date) as year from students group by month(join_date) - will not work

    select count(*) as students, month(join_date) as monthfrom students group by month(join_date) -- Will work fine.

    But there is no rule that the column that is grouped by should be retrived in the select stmt.This is evident in the below stmt,becoz students is not grouped and is also retrived.

    select count(*) ,name as student ,month(join_date) from students group by month(Join_date),year(join_date)--Works fine.

    I am also not sure, anyway depending on ur requirement u can adjust ur query.


    micky

  4. #4
    Join Date
    Jul 2003
    Posts
    3

    Help-me again please

    All,

    I forget that its base running in os/400.
    This sql run in db2 micro but not in mainframe.

    can somebody help-me?

    SQL:

    SELECT

    COUNT(*),
    MONTH(TS_INC)

    FROM

    DB2TBW.ISCR_TREN_ATVD

    GROUP BY MONTH(TS_INC)

  5. #5
    Join Date
    Mar 2003
    Location
    Singapore
    Posts
    200
    have u tried the queries i send to u(after changing the corresponding names).What is the result/error u get.

    I dont think there will be much change in the basic sql on any base.

    mickykt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •