Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9141519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:39:20+00:00 2026-06-17T09:39:20+00:00

How can I change the script below so I can do GROUP BY YR,

  • 0

How can I change the script below so I can do GROUP BY YR, QTR, CODE the value QTR_PCT gives to get my desired output?

CREATE VIEW REPORTS.MY_VIEW
(YR, QTR, QTR_PCT, CODE)
AS 
SELECT YR, QTR
, CASE WHEN PCTPERF>=85 THEN ROUND(AVG(PCTPERF)) 
  ELSE NULL
  END QTR_PCT
, CODE
FROM ANOTHER_VIEW
GROUP BY YR, QTR, PCTPERF, CODE
ORDER BY CODE ASC;

Actual Output: (I didn’t include column QTR_PCT)

+------+-----+------+
|   YR | QTR | CODE |
+------+-----+------+
| 2012 |   1 | 1039 | 
| 2012 |   1 | 1039 | 
| 2012 |   1 | 1039 |
| 2012 |   2 | 1039 | 
| 2012 |   2 | 1039 | 
| 2012 |   2 | 1039 |  
+------+-----+------+

Desired output: (I didn’t include column QTR_PCT)

+------+-----+------+
|   YR | QTR | CODE |
+------+-----+------+
| 2012 |   1 | 1039 | 
| 2012 |   2 | 1039 | 
+------+-----+------+
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:39:21+00:00Added an answer on June 17, 2026 at 9:39 am

    I’m not sure that I understand your question but maybe this can help, try:

    SELECT YR, qtr, code,max(qtr_pct)  aa
    FROM (
    SELECT YR, qtr, code, pctref,  CASE WHEN pctref >= 85 THEN round(avg(pctref) over (partition BY YEAR, qtr, code))
      ELSE NULL END qtr_pct
    FROM ANOTHER_VIEW) t
    GROUP BY YR, qtr, code;
    

    Here is a sqlfiddle demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hopefully I can get help from you guys..I got a simple script below but
How can I change the code below so instead of a text input type
Can someone give me a Powershell script that will change the format of all
I am wondering if I can change the value of io.sort.mb per job? I
I wrote the following Perl script (below) in order to create simple XML file.
In the script below, I want to keep the initial value of htmlStrTOCpre static
Can I pass a variable in hover()? As in the script below, I don't
I wonder whether someone can help me please. I'm using the code below to
The below code is to create a campaign. Before creation, I have to validate
Hope someone can help. I have the code below which when the user hovers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.