How can I change this query? to get the results I want
This query
select
SHRTGPA_pidm,
SZSTCLA_TERM_CODE,
SHRTGPA_GPA_HOURS
from szstcla,SHRTGPA
where szstcla_pidm = 74246
and SHRTGPA_pidm = szstcla_pidm
and SZSTCLA_TERM_CODE <> SZSTCLA_TERM_CODE_MATRIC
and SHRTGPA_TERM_CODE = SZSTCLA_TERM_CODE
Returns74246 201020 4
74246 201120 4
74246 201110 4
74246 201210 4
74246 201220 4
I want to group the query will return74246 201020 4
74246 201120 8
74246 201110 12
74246 201210 16
201220 20
Two copies
Published by: Frank Kulash, November 8, 2012 11:32
Tags: Database
Similar Questions
-
Windows 7 network connection status sent/received packets in bytes by default. How can I change this setting so that the status is displayed in MBs.
Hey Muhammad,
Thanks for posting the query on Microsoft Community.
Design/default it appears in bytes not in MB.
In the future, if you have problems with Windows, get back to us. We will be happy to help you.
-
I'm looking for only column compare to my same target table as a table source.
My query:
Select case when column_name_s is null and column_name_t is not null
then "alter table GRADE_CONVERSION drop | column_name_t | ';'
When column_name_s is not null and column_name_t is null
then "alter table GRADE_CONVERSION add | column_name_s | ' ' || data_type_s | « ; »
else 'alter table modify GRADE_CONVERSION | column_name_t | ' ' || data_type_t | « ; »
alterations of the end
from (select s.column_name column_name_s, t.column_name column_name_t,
s.data_type data_type_s, t.data_type data_type_t
(select column_name, column_id, data_type
of all_tab_cols@database
where owner = 'erhan.
and table_name = "GRADE_CONVERSION."
+ 1
full outer join
(select column_name, column_id, data_type
of all_tab_cols@database
where owner = 'sarigul.
and table_name = "GRADE_CONVERSION."
+ 6
on s.column_name = t.column_name
)
Tables:
Target table: table GRADE_CONVERSION in sarigul@database
LETTER_GRADE VARCHAR2 (2) GRADE_POINT NUMBER (3.2) MAX_GRADE NUMBER (3) MIN_GRADE NUMBER (3) Table source: Table GRADE_CONVERSION in erhan@database
LETTER_GRADE VARCHAR2 (2) GRADE_POINT NUMBER (3.2) MAX_GRADE NUMBER (3) MIN_GRADE NUMBER (3) CREATED_BY VARCHAR2 (30) CREATED_DATE DATE MODIFIED_BY VARCHAR2 (30) MODIFIED_DATE DATE want to see output that is similar to this * (please ignore the names of column here it's just a clear example :))
ALTER table Target_table change BOOK_ID Varchar2 (4);
ALTER table Target_table I addSBN_10 Varchar2(13), null;
ALTER table drop TITLE Target_table;
Erhan_toronto wrote:
1.I used src.nullable src_nullable and tgt.nullable tgt_nullable but only show Yes as below: but want to see the result as not null or null
ALTER table TEST_TARGET change the NUMBER of MAX_GRADE (3, 2) Yes
Ok. So it's all about the Yes and the no decoding to Default Null or Not Null, isn't it?
So, to test, change one of the table of sample for NOT NULL columns in the source table, and then run the following query:
with src as ( select src.table_name src_table_name, src.column_name src_col_name, src.data_type src_data_type, src.data_length src_data_len, src.data_precision src_data_precision, src.data_scale src_data_scale, src.nullable src_nullable from user_tab_columns src where table_name = 'TEST_SOURCE' ), tgt as ( select tgt.table_name tgt_table_name, tgt.column_name tgt_col_name, tgt.data_type tgt_data_type, tgt.data_length tgt_data_len, tgt.data_precision tgt_data_precision, tgt.data_scale tgt_data_scale, tgt.nullable tgt_nullable from user_tab_columns tgt where table_name = 'TEST_TARGET' ), col_details as ( select src.src_table_name, nvl(tgt.tgt_table_name, first_value(tgt_table_name) over(order by tgt_table_name nulls last)) tgt_table_name, src.src_col_name, src.src_data_type, src.src_data_len, src.src_data_precision, src.src_data_scale, src.src_nullable, tgt.tgt_col_name, tgt.tgt_data_type, tgt.tgt_data_len, tgt.tgt_data_precision, tgt.tgt_data_scale, tgt.tgt_nullable from src left outer join tgt on ( src.src_col_name = tgt.tgt_col_name ) ) select * from ( select case when tgt_data_type != src_data_type or tgt_data_len != src_data_len or tgt_data_precision != src_data_precision or tgt_data_scale != src_data_scale or src_nullable != tgt_nullable then 'alter table ' || tgt_table_name || ' modify ' || tgt_col_name || ' ' || src_data_type || ' (' || case when src_data_type in ('DATE') then null else case when src_data_type in ('VARCHAR', 'VARCHAR2') then nvl(to_char(src_data_len), ' ') || ') ' else decode(nvl(src_data_precision, -1), -1, null, nvl(to_char(src_data_precision), ' ') || ', ' || nvl(to_char(src_data_scale), ' ') || ')') end end || decode(src_nullable, 'NO', ' NOT NULL', ' DEFAULT NULL') when tgt_col_name is null then 'alter table ' || tgt_table_name || ' add ' || src_col_name || ' ' || src_data_type || case when src_data_type in ('DATE') then null else case when src_data_type in ('VARCHAR', 'VARCHAR2') then nvl(to_char(src_data_len), ' ') || ') ' else decode(nvl(src_data_precision, -1), -1, null, nvl(to_char(src_data_precision), ' ') || ', ' || nvl(to_char(src_data_scale), ' ') || ')') end end || decode(src_nullable, 'NO', ' NOT NULL', ' DEFAULT NULL') end alter_statement from col_details ) where alter_statement is not null;
Erhan_toronto wrote:
2. when I run below under user sarigul and erhan I get the result as OWNER, TABLE_NAME, COLUMN_NAME DATA_TYPE... I have a link between two users. They have access to two tables.
- Select * from all_tab_columns
where owner = 'erhan' and table_name = "TEST_SOURCE."
- Select * from all_tab_columns
where owner = 'sarigul' and table_name = "TEST_TARGET."
Alright. This means that you both users are on the same database. Only change, you will have to do in the above query is so change user_tab_columns to all_tab_columns and add the OWNER predicate respectively with the clause.
-
How can I change this query to generate a sequence
This query
Returns the following resultsselect SZSTCLA_PIDM, SZSTCLA_TERM_CODE, SZSTCLA_LAST_NAME from SZSTCLA,SHRTGPA where SZSTCLA_PIDM IN ( 120125,186114) AND SHRTGPA_TERM_CODE = SZSTCLA_TERM_CODE AND shrtgpa_pidm = SZSTCLA_PIDM AND SZSTCLA_RECORDED_EARNED_CRED > 0 ORDER BY SZSTCLA_TERM_CODE
Notice that ruptures in every szstcla_pidm, I need to change the query, so it can display a sequence number for each SZSTCLA_TERM_CODESZSTCLA_PIDM SZSTCLA_TERM_CODE SZSTCLA_LAST_NAME 186114 198810 Johnson 186114 198820 Johnson 186114 198910 Johnson 186114 198920 Johnson 186114 199010 Johnson 186114 199020 Johnson 186114 199110 Johnson 186114 199120 Johnson 120125 200720 Smith 120125 200810 Smith 120125 200820 Smith 120125 200910 Smith 120125 200920 Smith 120125 201010 Smith 120125 201020 Smith 120125 201110 Smith 120125 201120 Smith
so, it will be like
thenSZSTCLA_PIDM SZSTCLA_TERM_CODE SZSTCLA_LAST_NAME seq 186114 198810 Johnson 1 186114 198820 Johnson 2 186114 198910 Johnson 3 186114 198920 Johnson 4 186114 199010 Johnson 5 186114 199020 Johnson 6 186114 199110 Johnson 7 186114 199120 Johnson 8
SZSTCLA_PIDM SZSTCLA_TERM_CODE SZSTCLA_LAST_NAME seq 120125 200720 Smith 1 120125 200810 Smith 2 120125 200820 Smith 3 120125 200910 Smith 4 120125 200920 Smith 5 120125 201010 Smith 6 120125 201020 Smith 7 120125 201110 Smith 8 120125 201120 Smith 9
Looks like below, this is what you are looking for, but I can't understand why some documents are missing from the sample output
COL1 COL2 SZSTCLT_LAST_NAME RN -------- -------- ------------------------------ -- 120125 200920 Smith 1 120125 201010 Smith 2
Maybe, if you could explain it, the query can be modified to exclude these folders as well. But, for now, downwards should suffice.
select szstclt_pidm col1, szstclt_term_code col2, szstclt_last_name, row_number() over (partition by szstclt_pidm order by szstclt_term_code) rn from szstclt a join shrtgpt b on a.SZSTCLT_PIDM = b.SHRTGPT_PIDM and a.SZSTCLT_TERM_CODE = b.SHRTGPT_TERM_CODE where SZSTCLT_PIDM IN ( 120125,186114); COL1 COL2 SZSTCLT_LAST_NAME RN -------- -------- ------------------------------ -- 120125 200920 Smith 1 120125 201010 Smith 2 120125 201020 Smith 3 120125 201110 Smith 4 120125 201120 Smith 5 186114 198810 Johnson 1 186114 198820 Johnson 2 186114 198910 Johnson 3 186114 198920 Johnson 4 186114 199010 Johnson 5 186114 199020 Johnson 6 186114 199110 Johnson 7 186114 199120 Johnson 8 13 rows selected
-
My screen vertically and not horizontally. How can I change this back?
OT: Screen display.
My child has touched something on my computer and now my screen vertically and not horizontally. How can I change this back?
Wednesday, February 11, 2015 14:23 + 0000, anniemontcalm wrote:
My child has touched something on my computer and now my screen vertically and not horizontally. How can I change this back?
The ability to rotate the screen image is a characteristic of your video
card, to help work with instructors who turn to the portrait
orientation. Certainly he accidentally pressed Ctrl-Alt, and
an arrow key.Rotate using these keys.
-
I did a restore of my backup cd. The icons are still adobe. I can't get into the programs when I click on the icon. If not, how can I change this back to what they were?
Thank you
[Moved from the forum comments]
Hi Marlayne,
Thanks for posting your query on the Microsoft Community.
Could you please answer the following questions so that I can help you best.
1. what operating system do you use?
You can check this link for the operating system.
http://Windows.Microsoft.com/en-us/Windows/which-operating-system
2 are. what icons you referring?
3. what programs you're talking about?
4. What happen exactly when you click the icon?
5. you receive an error message when you try to open the programs?I suggest you to try the fixit from the link below.
Diagnose and repair Windows files and folders problems automatically
http://support.Microsoft.com/mats/windows_file_and_folder_diag/Hope the above information helps.
Do get back to us and let us know the State of the issue of your next post or in the cases where you need assistance about Windows.
-
I changed my email address but my weekly activity reports are sent to my old email address always, how can I change this?
All my account settings read my new email address, but in the security settings for the family where it shows you where your children's accounts are linked to its display of my old email address but I am unable to change it. Is could someone please tell me how to update the email address?
Hi Rachel,
Thanks for posting your query in Microsoft Community.
I suggest you to check out the article below and check if it helps.
Change the address where should be sent the reports of parental control
Please get back to us if you need further assistance.
-
How can I change this request, so I can display the name and partitions in a r
How can I change this request, so I can add the ID of the table SPRIDEN
from now on gives me what I want:
in a single line, but I would like to add the id and the name that is stored in the SPRIDEN table1,543 A05 24 A01 24 BAC 24 BAE 24 A02 20 BAM 20
SELECT sortest_pidm, max(decode(rn,1,sortest_tesc_code)) tesc_code1, max(decode(rn,1,score)) score1, max(decode(rn,2,sortest_tesc_code)) tesc_code2, max(decode(rn,2,score)) score2, max(decode(rn,3,sortest_tesc_code)) tesc_code3, max(decode(rn,3,score)) score3, max(decode(rn,4,sortest_tesc_code)) tesc_code4, max(decode(rn,4,score)) score4, max(decode(rn,5,sortest_tesc_code)) tesc_code5, max(decode(rn,5,score)) score5, max(decode(rn,6,sortest_tesc_code)) tesc_code6, max(decode(rn,6,score)) score6 FROM (select sortest_pidm, sortest_tesc_code, score, row_number() over (partition by sortest_pidm order by score desc) rn FROM (select sortest_pidm, sortest_tesc_code, max(sortest_test_score) score from sortest,SPRIDEN where SPRIDEN_pidm =SORTEST_PIDM AND sortest_tesc_code in ('A01','BAE','A02','BAM','A05','BAC') and sortest_pidm is not null GROUP BY sortest_pidm, sortest_tesc_code)) GROUP BY sortest_pidm;
Hello
That depends on whether spriden_pidm is unique, and you want to get the results.
Whenever you have a problem, post a small example of data (CREATE TABLE and INSERT, relevamnt columns only instructions) for all the tables and the results desired from these data.
If you can illustrate your problem using tables commonly available (such as in the diagrams of scott or HR) so you need not display the sample data; right after the results you want.
Whatever it is, explain how you get these results from these data.
Always tell what version of Oracle you are using.Looks like you are doing something similar to the following.
Using the tables emp and dept of the scott schema, producing a line of production by Department showing the highest salary for each job, for a set given jobs:DEPTNO DNAME LOC JOB_1 SAL_1 JOB_2 SAL_2 JOB_3 SAL_3 ------ -------------- ------------- ------- ----- ------- ----- ------- ----- 20 RESEARCH DALLAS ANALYST 3000 MANAGER 2975 CLERK 1100 10 ACCOUNTING NEW YORK MANAGER 2450 CLERK 1300 30 SALES CHICAGO MANAGER 2850 CLERK 950
On each line, jobs are listed in order by the highest salary.
This seems to be similar to what you are doing. The roles played by the sortest_pidm, sortest_tesc_code and sortest_test_score in your table sortest are played by deptno, job and sal in the emp table. The roles played by the spriden_pidm, id and the name of your table spriden are played by deptno, dname and loc in the dept table.Looks like you already have something like the query below, which produces a correct output, except that it does not include the dname and loc of the dept table columns.
SELECT deptno , MAX (DECODE (rn, 1, job)) AS job_1 , MAX (DECODE (rn, 1, max_sal)) AS sal_1 , MAX (DECODE (rn, 2, job)) AS job_2 , MAX (DECODE (rn, 2, max_sal)) AS sal_2 , MAX (DECODE (rn, 3, job)) AS job_3 , MAX (DECODE (rn, 3, max_sal)) AS sal_3 FROM ( SELECT deptno , job , max_sal , ROW_NUMBER () OVER ( PARTITION BY deptno ORDER BY max_sal DESC ) AS rn FROM ( SELECT e.deptno , e.job , MAX (e.sal) AS max_sal FROM scott.emp e , scott.dept d WHERE e.deptno = d.deptno AND e.job IN ('ANALYST', 'CLERK', 'MANAGER') GROUP BY e.deptno , e.job ) ) GROUP BY deptno ;
Dept.DeptNo is unique, it won't be a dname and a loc for each deptno, so we can modify the query by replacing "deptno" with "deptno, dname, loc" throughout the query (except in the join condition, of course):
SELECT deptno, dname, loc -- Changed , MAX (DECODE (rn, 1, job)) AS job_1 , MAX (DECODE (rn, 1, max_sal)) AS sal_1 , MAX (DECODE (rn, 2, job)) AS job_2 , MAX (DECODE (rn, 2, max_sal)) AS sal_2 , MAX (DECODE (rn, 3, job)) AS job_3 , MAX (DECODE (rn, 3, max_sal)) AS sal_3 FROM ( SELECT deptno, dname, loc -- Changed , job , max_sal , ROW_NUMBER () OVER ( PARTITION BY deptno -- , dname, loc -- Changed ORDER BY max_sal DESC ) AS rn FROM ( SELECT e.deptno, d.dname, d.loc -- Changed , e.job , MAX (e.sal) AS max_sal FROM scott.emp e , scott.dept d WHERE e.deptno = d.deptno AND e.job IN ('ANALYST', 'CLERK', 'MANAGER') GROUP BY e.deptno, d.dname, d.loc -- Changed , e.job ) ) GROUP BY deptno, dname, loc -- Changed ;
In fact, you can continue to use just deptno in the analytical PARTITION BY clause. It may be slightly more efficient to just use deptno, as I did above, but it won't change the results if you use all 3, if there is only 1 danme and 1 loc by deptno.
Moreover, you don't need so many subqueries. You use the internal subquery to calculate the MAX and the outer subquery to calculate rn. Analytical functions are calculated after global fucntions so you can do both in the same auxiliary request like this:
SELECT deptno, dname, loc , MAX (DECODE (rn, 1, job)) AS job_1 , MAX (DECODE (rn, 1, max_sal)) AS sal_1 , MAX (DECODE (rn, 2, job)) AS job_2 , MAX (DECODE (rn, 2, max_sal)) AS sal_2 , MAX (DECODE (rn, 3, job)) AS job_3 , MAX (DECODE (rn, 3, max_sal)) AS sal_3 FROM ( SELECT e.deptno, d.dname, d.loc , e.job , MAX (e.sal) AS max_sal , ROW_NUMBER () OVER ( PARTITION BY e.deptno ORDER BY MAX (sal) DESC ) AS rn FROM scott.emp e , scott.dept d WHERE e.deptno = d.deptno AND e.job IN ('ANALYST', 'CLERK', 'MANAGER') GROUP BY e.deptno, d.dname, d.loc , e.job ) GROUP BY deptno, dname, loc ;
It will work in Oracle 8.1 or more. In Oracle 11, however, it is better to use the SELECT... Function PIVOT.
-
When I delete emails from my iPhone 5, same emails deleted from my Mac desktop. There are a lot of emails that I want to keep on my desk that I don't want to keep on my phone, for reasons of capacity and convenience. This link happened recently - before that, I could remove the phone without deleting the computer. How can I change this?
This looks like what an IMAP email account made by design. This isn't a matter of Apple.
Is what email provider? How do you account set up?
Get help if you have any questions using a POP email with multiple devices - Apple Support account
-
I have outlook express and the spell checker is for the French. How can I change this?
I have outlook express and the spell checker is for the French. How can I change this?
You no longer have the correction spell checking capabilities in some languages in Outlook Express 6.0 after you install the Microsoft Office 2007 or Office 2010 system
http://support.Microsoft.com/kb/932974Outlook Express cannot use the check spelling of MS Word in Office 2007 or newer. A free spell-checking the download is the easiest way to get around this.
Vampirefo spell check.
Download from Major Geeks:
http://www.MajorGeeks.com/download.php?Det=2952Or upload it to SnapFile:
http://www.SnapFiles.com/get/spelloe.htmlYou wanted TinySpell or. (Check spelling while typing).
Download it here:
http://www.tinyspell.M6.NET/Australian English spell checking
(Also suitable for other English speaking countries).
http://www.justlocal.com.au/clients/oespellcheck/If you have an earlier version of Office, see this:
http://www.Outlook-tips.NET/archives/2006/20061228.htmBruce Hagen
MS - MVP October 1, 2004 ~ September 30, 2010
Imperial Beach, CA -
Vista fails to winzip, how can I change this?
Vista fails to winzip, how can I change this to get vista do the zip and unzip as it should?
Whenever I try to open a zipped file, Vista winzip default (I did a test of it). When I right click and choose open with, it shows only IE and Winzip as choice. I know that Vista has it's own built in 'zipper', but I have no idea how to get the default value to the operating system for this function.
Vista 64 bit, on an Intel Quad
Right click and choose Extract all not open with. If you do not use uninstall Winzip's default Windows needs to be restored, otherwise post back for more information. If you uninstall Winzip and open with still shows Winzip I'll tell you how to remove it.
-
When I send an email or an attachment it happen as the benefits of discovery as the sender and not my name, how can I change this? his strange huh?
I never stay connected to my email, I actually get hacked somehow I have change my password often enough
Hi darenlysne,
It sounds like you have the email account of incorrect installation and hurt the server info.
Provide the program that you are using and we can go from there, or contact your ISP.
B Eddie
-
I have a gateway laptop, but windows 7 is in Spanish, how can I change this
I have a gateway laptop, but windows 7 is in Spanish, how can I change this
Hello
Which edition of Windows 7 work?
Spanish and English are the two main languages. The only way to change a language on the computer if it's the Ultimate or Enterprise Windows version installed.
Windows 7 language packs are available for computers that are running Windows 7 ultimate or Windows 7 Enterprise
http://support.Microsoft.com/kb/972813
If you have one of these versions of Windows, see Windows 7 language packs on the following Web site.
How can I get additional display languages?
http://Windows.Microsoft.com/en-us/Windows7/how-do-I-get-additional-display-languagesInstall or change a display language
http://Windows.Microsoft.com/en-us/Windows7/install-or-change-a-display-language
Let us know if it helps!
-
I bought Photoshop elements 14 for my mac, but was sent to a download of windows. How can I change this?
Please contact support and ask for an Exchange. They should be able to provide one without penalty or loss of the ability to change platform in the future. This seems to happen too often a mistake of the buyer.
To the link below, click on the still need help? option in the blue box below and choose the option to chat or by phone...
Make sure that you are logged on the Adobe site, having cookies enabled, clearing your cookie cache. If it fails to connect, try to use another browser.Get help from cat with orders, refunds and exchanges (non - CC)
http://helpx.Adobe.com/x-productkb/global/service-b.html ( http://adobe.ly/1d3k3a5 ) -
When I download a video or a file, the alert when you have finished its is very strong and unpleasant. How can I change this alert?
I find the problem in an add-on as suggested you do that of the add-on sound came and stopped. Thanks for all the help.
I tried to mark it as resolved, but said access denied oh well.
Maybe you are looking for
-
how the firefox prevented the obsolete plugin 'adobe flash' race
What reasons that make firefox prevented the obsolete "adobe flash" plugin a few times running on Web sites.
-
Can't use recovery error 'Machine wrongly' DVD occurs
My Center dealer/replaced motherboard, when I had a problem starting. My recovery DVDs that originally comes with the laptop no longer works. When I start recovery procedure followed by message is displayed: "Machine wrongly". Is it possible to downl
-
Apple TV 3 frequently stops and restarts all streaming Netflix
This happens at least once during a movie. After it restarts automatically, you must work your way to the content you were viewing and resume watching. It happens so often now that it becomes very annoying.
-
EA4500 Port Forawarding with Firmware 2.1.39.145204
I've recently updated to firmware as mentioned in the subject and am almost to a State that I decided to go back. I can't do a port forwarding and or locate the section to the GUI. The old GUI had placed very simply, so he could enter this function.
-
When to play clips on the timeline, it goes to the black screen
Original title: on windows Movie maker, I always get a black when playing screen its in the timeline, but when I play a clip before I put it in the timeline panel, it works, someone help!in order to clearly indicate the clip in = black not in the tim