PS Query & SQL

 View Only
  • 1.  Can't Join TERM_VAL_TBL

    Posted 12 days ago

    I'm working modifying a courses last offered query by adding the term description from the TERM_VAL_TBL. Unfortunately, this isn't working as expected because I'm receiving an 'Error in running query because of SQL Error, Code=934, Message=ORA-00934: group function is not allowed here (50,380)' message. I think this is because CLASS_TBL is looking for the maximum STRM - when I remove the criteria it runs successfully, but for every term. Any suggestions for how I can resolve this error?

    Here's my SQL if it is helpful:
        
    SELECT DISTINCT A.CRSE_ID, TO_CHAR(A.EFFDT,'YYYY-MM-DD'), B.CATALOG_PRINT, B.SUBJECT, B.CATALOG_NBR, A.DESCR, B.SSR_CRSE_TYPOFF_CD, D.DESCR, MAX( C.STRM)
      FROM PS_CRSE_CATALOG A, (PS_CRSE_OFFER B LEFT OUTER JOIN  PS_CLASS_TBL C ON  B.CRSE_ID = C.CRSE_ID AND B.CRSE_OFFER_NBR = C.CRSE_OFFER_NBR ), PS_SSR_CRSE_TYPOFF D, PS_TERM_VAL_TBL E
      WHERE ( D.SSR_CRSE_TYPOFF_CD = B.SSR_CRSE_TYPOFF_CD
        AND D.INSTITUTION = B.INSTITUTION
        AND ( A.EFFDT =
            (SELECT MAX(A_ED.EFFDT) FROM PS_CRSE_CATALOG A_ED
            WHERE A.CRSE_ID = A_ED.CRSE_ID)
         AND A.CRSE_ID = B.CRSE_ID
         AND B.EFFDT =
            (SELECT MAX(B_ED.EFFDT) FROM PS_CRSE_OFFER B_ED
            WHERE B.CRSE_ID = B_ED.CRSE_ID
              AND B_ED.EFFDT <= SYSDATE)
         AND D.EFFDT =
            (SELECT MAX(D_ED.EFFDT) FROM PS_SSR_CRSE_TYPOFF D_ED
            WHERE D.INSTITUTION = D_ED.INSTITUTION
              AND D.SSR_CRSE_TYPOFF_CD = D_ED.SSR_CRSE_TYPOFF_CD
              AND D_ED.EFFDT <= B.EFFDT)
         AND MAX( C.STRM) = E.STRM ))
      GROUP BY  A.CRSE_ID,  A.EFFDT,  B.CATALOG_PRINT,  B.SUBJECT,  B.CATALOG_NBR,  A.DESCR,  B.SSR_CRSE_TYPOFF_CD,  D.DESCR
      ORDER BY 1



    ------------------------------
    Pheng Xiong
    Senior Associate Registrar
    Rochester Institute of Technology
    ------------------------------

    Message from the HEUG Marketplace:
    ------------------------------
    Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the HEUG Marketplace.
    ------------------------------
    Alliance 2026 Registration is Open!


  • 2.  RE: Can't Join TERM_VAL_TBL

    Posted 12 days ago

    The problem is that anytime you use max as an aggregate on a field, it uses it EVERY place that field is referenced.  This results in the following SQL problem...

     

    Which isn't allowed.  The easiest fix is to not use max on the actual field, but to create an expression with the aggregate box checked, and put in max (c.strm) as the expression.  Use that field, and you should be ok.  I think.  If I'm remembering correctly...

     

    Thanks!

     

    Vic

    ---

    Vic Goldberg

    Retiree, Temporary Employee

    University of Colorado Boulder

    Independent PeopleSoft FA Consultant

     

     




    Alliance 2026 Registration is Open!


  • 3.  RE: Can't Join TERM_VAL_TBL

    Posted 12 days ago
    Edited by Pheng Xiong 12 days ago

    Thanks Vic. I initially had it set as an expression as you noted, but the issue is that the term table will display the description for every term the class was offered, ignoring the expression. Here i a screen capture of what I saw when I used the expression of max(STRM) with and without the TERM_VAL_TBL.

    Notice how below, it ignores the expression and provides the description for all terms.



    ------------------------------
    Pheng Xiong
    Senior Associate Registrar
    Rochester Institute of Technology
    ------------------------------

    Message from the HEUG Marketplace:
    ------------------------------
    Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the HEUG Marketplace.
    ------------------------------

    Alliance 2026 Registration is Open!


  • 4.  RE: Can't Join TERM_VAL_TBL

    Posted 12 days ago

    Hello Pheng,

    You may want try making STRM equal to a subquery where you select STRM and make it the max value in the subquery.  The SQL would look similar to the following (I am using a different table):

    WHERE A.STRM = (SELECT MAX( B.STRM)
      FROM PS_FAN_FA_TERM_VW B
      WHERE B.EMPLID = A.EMPLID
         AND B.INSTITUTION = A.INSTITUTION)

    Let me know if screenshots would help more.



    ------------------------------
    Daniel Labrecque
    Oracle Consulting Manager
    Huron Consulting Group
    ------------------------------

    Message from the HEUG Marketplace:
    ------------------------------
    Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the HEUG Marketplace.
    ------------------------------

    Alliance 2026 Registration is Open!


  • 5.  RE: Can't Join TERM_VAL_TBL

    Posted 12 days ago

    Thank you, Daniel. That seems to have worked. I didn't think about a subquery.



    ------------------------------
    Pheng Xiong
    Senior Associate Registrar
    Rochester Institute of Technology
    ------------------------------

    Message from the HEUG Marketplace:
    ------------------------------
    Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the HEUG Marketplace.
    ------------------------------

    Alliance 2026 Registration is Open!


  • 6.  RE: Can't Join TERM_VAL_TBL

    Posted 12 days ago
    Hi Pheng.

    Vic's response should absolutely fix the error you are experiencing. PSQuery likes to try to do some thinking for you when you use the aggregate functions on the fields themselves. It thinks that EVERY instance of that field in the SQL should be an aggregate too - which is hardly ever what we want.

    In my experience, the best practice is to set all of your aggregates in the expressions so that you have full control of when you aggregate things.

    That said, while using an expression will resolve the error, it still might not be sufficient to get the desired results. Since you are returning the D.DESCR in your output, the query is going to use that in your GROUP BY expression, and might result in duplicate rows.

    To get around this, you can create a subquery that replicates the logic at the top SELECT level, and join that to your D.TERM. Or you could use an expression. I don't know your term structure, but something like: 

    SUBSTR(
        MAX(C.STRM || ';' || D.DESCR)
        ,INSTR(MAX(C.STRM || ';' || D.DESCR),';')+1,100)

    Seems like it would work - unless you natively use semicolons in your term structure.
    --
    Jeffrie Brooks | BUSINESS SYSTEM ANALYST
    UNIVERSITY OF MICHIGAN | INFORMATION AND TECHNOLOGY SERVICES
    734-647-8763 | jedobr@umich.edu



    Alliance 2026 Registration is Open!