Select column 1 into two column from same table
Dear Sir
I have a data like
studid makr tottal credit total average mark semester
251; 249.84; 41; 6.09; 1
106; 285.32; 42; 6.79; 1
285; 263.88; 38; 6.94; 1
251; 202.40; 28; 7.23; 2
106; 293.20; 39; 7.52; 2
285; 228.14; 39; 5.85; 2
I want to select average mark semester1 and semester 2 in different column
studid average_mark_ semester1 average_ mark_ semester_ 2
251 6.09 7.23
106 6.79 7.52
285 6.94 5.85
please help me
regards
sanat kumar
thanks in advance
Dear Sir,
Thank u for your prompt answer.
But I want to select student id and average mark based on semester
out put supposed to be
student id average_makr_sem1 average_mark_sem2
251 6.09 7.23
106 6.79 7.52
285 6.94 5.85
I want to select the average mark in different column based on semester
Please look into
thanks
regards
sanat
Similar Messages
-
Splitting one column into two columns
Hi,
How to create two columns in one column header using JTable swing concept in java.
Thanks in advance[http://forum.java.sun.com/thread.jspa?threadID=488822&messageID=2297054]
you can use MultiLineHeaderRenderer class for this purpose. search for that class and examples
sunil -
Displaying the values from a single column into two columns???
hi buddies.....I've a table "Stock" and its fields are:
Date, Invoice#, prod_id, sal_qty, pur_qty, rate, status
The "rate" column stores the rate value on which a product was sold or purchased and "status" column values are like "S" for Sale,"OP" for opening and "P" for purchase.
The problem here to me is that I'm unable to pick the purchase & sale rate of a product based on the status either "S" or "P". Is it possible to pick the purchase rate of a product sold between a specified limit of dates??? and show both sale & purchase rates in two separate columns in the result sets for a given product in a specified duration. The resulte set format should be like this:
Prod_id Sale_Rate Pur_RateDear Dmitri,
Let me tell u my case more elaborately so that u can have a better insight on my problem. I've a Stock table to which I'm trying to use to calculate current stock quantity, its value and profit per sale transaction. It has following simple description.
Stock_Table:
Invoice# Date Product Batch# Sale_QTY Pur_QTY Rate Status
Pur-001 01/01/05 Asprin AB123 0 100 10 OP --(Opening)
Pur-002 02/01/05 Paracetamol CD456 0 150 15 OP
Pur-002 03/01/05 Menthol XY333 0 80 7 OP
Pur-003 01/01/05 Asprin ZZ990 0 50 8 P ..(Purchase)
Sale001 02/01/05 Asprin AB123 10 0 2 S
Sale001 02/01/05 Paracetamol CD456 5 0 16 S ..(Sale)
Sale002 04/01/05 Asprin ZZ990 6 0 10 S
Sale002 04/01/05 Paracetamol CD456 7 0 20 S
Sale002 04/01/05 Menthol XY333 4 0 10 S
From this design can u calulate the difference of sale & purchase rate of a product during a range of dates(which is the Profit)? i.e firstly pick a sale transaction and then minus the purchase rate of the product from the sale rate in that sale transaction by looking at the product name and its batch number.
While solving this case, please keep in mind that I'm using Oracle 8.0 which doesn't support inlined Sub-Query(a query within FROM clause). So giving u a hint(although I'm not genious enough;), I tried the Self Join at Stock Table by picking the sale rows at first and then purchase rows afterwords by giving this table two different names. I also tried the following query by joining the Sale Table with Stock Table. Is it the right way I'm heading towards???
SELECT S.Sale_Date, SD.Invoice#, SD.Product, SD.QTY, SD.Rate Sale_Rate,
ST.Rate Pur_Rate, ST.Product
FROM Invoice_Master S, Invoice_Detail SD, Stock ST
WHERE S.Invoice# = SD.Invoice#
AND ST.Status IN('OP','P')
AND ST.Product = SD.Product
AND S.Sale_Date BETWEEN :From_Date AND :To_Date
AND SD.Product = P.Product
ORDER BY S.Sale_Date -
Combine 2 Queries (from SAME table) into a SINGLE query
I have this two queries (from SAME table), and want to combine into one SINGLE query, how?
How can we use CASE WHEN THEN for such situation?
Query1:
SELECT t_inner.*,
Floor(t_inner.ProductiveTime/ 3600) || 'hr:' || LPAD(Floor(Mod(t_inner.ProductiveTime,3600) / 60),2,0) || 'min:' AS Productive_Time,
Floor(t_inner.OperatorDownTime/ 3600) || 'hr:' || LPAD(Floor(Mod(t_inner.OperatorDownTime,3600) / 60),2,0) || 'min:' AS OperatorDown_Time
FROM
(SELECT SYSTEMTYPE,
sum(TIME_TEST + TIME_STEP) AS ProductiveTime,
sum(TIME_IDLE) AS OperatorDownTime
FROM PFODS.PPL_TESTSYSTEMS_UTILISATION
WHERE (SYSTEMTYPE = '0005-072')
AND (TS_START >= to_date('13/01/2014', 'DD/MM/YYYY'))
AND TS_End <= to_date('17/01/2014', 'DD/MM/YYYY') + 1 + (1/1440) +(59/86400)
AND MONO != '9999999999'
GROUP BY SYSTEMTYPE ) t_inner
Query 2:
SELECT t_inner.*,
Floor(t_inner.MachineDownTime/ 3600) || 'hr ' || LPAD(Floor(Mod(t_inner.MachineDownTime,3600) / 60),2,0) || 'min' AS MachineDown_Time
FROM
(SELECT SYSTEMTYPE,
sum(TIME_IDLE) AS MachineDownTime
FROM PFODS.PPL_TESTSYSTEMS_UTILISATION
WHERE (SYSTEMTYPE = '0005-072')
AND (TS_START >= to_date('13/01/2014', 'DD/MM/YYYY'))
AND TS_End <= to_date('17/01/2014', 'DD/MM/YYYY') + 1 + (1/1440) +(59/86400)
AND MONO = '9999999999'
GROUP BY SYSTEMTYPE) t_inner
see http://postimg.org/image/koq87iyyz/ and
http://postimg.org/image/fv3zxa38nwith the first query,
SELECT t_inner.*,
Floor(t_inner.ProductiveTime/ 3600) || 'hr:' || LPAD(Floor(Mod(t_inner.ProductiveTime,3600) / 60),2,0) || 'min' AS Productive_Time
FROM
(SELECT SYSTEMTYPE,
--sum(TIME_TEST) AS TIME_TEST,
--sum(TIME_SYSTEM) AS TIME_SYSTEM,
--sum(TIME_STEP) AS TIME_STEP,
--sum(TIME_IDLE) AS TIME_IDLE,
sum(TIME_TEST + TIME_STEP) AS ProductiveTime
FROM PFODS.PPL_TESTSYSTEMS_UTILISATION
WHERE (SYSTEMTYPE = '0005-072')
AND (TS_START >= to_date('13/01/2014', 'DD/MM/YYYY'))
AND TS_End <= to_date('17/01/2014', 'DD/MM/YYYY') + 1 + (1/1440) +(59/86400)
AND MONO != '9999999999'
GROUP BY SYSTEMTYPE) t_inner
it gives output as from
http://postimg.org/image/koq87iyyz/
with the second query,
SELECT t_inner.*,
Floor(t_inner.MachineDownTime/ 3600) || 'hr ' || LPAD(Floor(Mod(t_inner.MachineDownTime,3600) / 60),2,0) || 'min' AS MachineDown_Time
FROM
(SELECT SYSTEMTYPE,
sum(TIME_IDLE) AS MachineDownTime
FROM PFODS.PPL_TESTSYSTEMS_UTILISATION
WHERE (SYSTEMTYPE = '0005-072')
AND (TS_START >= to_date('13/01/2014', 'DD/MM/YYYY'))
AND TS_End <= to_date('17/01/2014', 'DD/MM/YYYY') + 1 + (1/1440) +(59/86400)
AND MONO = '9999999999'
GROUP BY SYSTEMTYPE) t_inner
it gives output as from
http://postimg.org/image/fv3zxa38n/
I want to come those 2 queries into a single query, such that it gives both outputs as above. Let me know if you need any other information. thanks. -
Need to Convert Comma separated data in a column into individual rows from
Hi,
I need to Convert Comma separated data in a column into individual rows from a table.
Eg: JOB1 SMITH,ALLEN,WARD,JONES
OUTPUT required ;-
JOB1 SMITH
JOB1 ALLEN
JOB1 WARD
JOB1 JONES
Got a solution using Oracle provided regexp_substr function, which comes handy for this scenario.
But I need to use a database independent solution
Thanks in advance for your valuable inputs.
GeorgeGo for ETL solution. There are couple of ways to implement.
If helps mark -
How do I turn selected text in a Pages document into two columns without turning the whole document into two columns?
Menu > Insert > Layout Break (before and after text) > click in text > Inspector > Layout > Layout > columns: 2
Peter -
Merge Two Rows of a table to One row but into two columns
Hi
I Am struck in writing a query to merge two rows into two columns of one row.
Here is the Sample data i am working with,
Col 1 Col 2 Col3 Col4 Col Col6
5000 573-3000 2 0 Phone
5000 573-3036 1 0 Fax
5000 893-5703 3 0 WOrk
3000 232-5656 1 0 Phone
3000 353-5656 2 0 FAx
Here Col,Col3,Col4 form the Key.
now wht i am trying to do is to Merge these type of rows put them into Columns P,F,W,E respectively to achive a Structure as below
Col1 P F W
5000 573-3000 573-3036 893-5703
3000 232-5656 353-5656
Can you please help me how could i do this.
I am pretty ordinary at writing SQL's.
Thanks a Lot in Advance
Message was edited by:
SreebhushanSearch the forum for PIVOT and you'll find plenty of examples.
-
Split one column value into two columns using t-sql
Hi All,
I have one varchar column in a table.
Col1
ABC-12C4
BC-A345
CD
XYZ
How to split this into two columns like this using t-sql
Col1 Col2
ABC 12C4
BC A345
CD
XYZ
Thanks,
RH
sqlassuming a static delimiter, and the split will end up with a max of 2 columns, something like this would work. basically you just need to determine where the delimiter is, and then use the left and right functions to find the 2 pieces.
declare @t table(value varchar(10))
insert into @t(value)
values
('ABC-12C4'), ('BC-A345'), ('CD'), ('XYZ')
select
case
when charindex('-', value) != 0 then left(value, charindex('-', value) - 1)
else value
end as col1,
case
when charindex('-', value) != 0 then right(value, len(value) - charindex('-', value))
else ''
end as col2
from @t -
Select multiple column into one column
Hi..!!!
Is it possible to select 4 columns in to 1 columns?
I've major1, major 2, major 3, major 4 and i want to retrieve all the columns into one column called "Majors".
Is it possible? if yes then how?
Help me out.
Thanks,
HimadriIf you had given a proper example this thread would have been over in two posts. What you are looking for is often described as an UNPIVOT.
I tend to use a collection type for this, e.g.
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> CREATE OR REPLACE TYPE varchar2_table AS TABLE OF VARCHAR2 (4000);
2 /
Type created.
SQL> SELECT empno, column_value
2 FROM emp, TABLE (varchar2_table (ename, job));
EMPNO COLUMN_VALUE
7369 SMITH
7369 CLERK
7499 ALLEN
7499 SALESMAN
7521 WARD
7521 SALESMAN
7566 JONES
7566 MANAGER
7654 MARTIN
7654 SALESMAN
7698 BLAKE
(snipped)
28 rows selected.
SQL> -
Split the column into two based on conditions
Hello,
I have 2 tables Country and Continent.
Continent has the data like this
ID Name
1 Asia
2 Africa
3 North America
4 South America
Country has
ID Name ContinentID Population
1 China 1 2000
2 India 1 1500
3 Ethiopia 2 7500
4 United States 3 5000
I need the count of countries for each continent break into two columns based on the population. One column showing the count of countries with population <= 2000 and the other column should show the count of countries with population >2000
How can I achieve this?
Please help.
Thank youHere you go:
DECLARE @continent TABLE (ID INT, Name VARCHAR(30))
INSERT INTO @continent (ID, Name) VALUES (1, 'Asia' ),(2, 'Africa' ),(3, 'North America'),(4, 'South America')
DECLARE @country TABLE (ID INT, Name VARCHAR(30), ContinentID INT, Population INT)
INSERT INTO @country (ID, Name, ContinentID, Population) VALUES (1, 'China', 1, 2000),(2, 'India', 1, 1500),(3, 'Ethiopia', 2, 7500),(4, 'United States', 3, 5000)
SELECT COUNT(*), ct.name
FROM @country c
INNER JOIN @continent ct
ON c.ContinentID = ct.ID
GROUP BY ct.name
and for the high/low:
DECLARE @continent TABLE (ID INT, Name VARCHAR(30))
INSERT INTO @continent (ID, Name) VALUES (1, 'Asia' ),(2, 'Africa' ),(3, 'North America'),(4, 'South America')
DECLARE @country TABLE (ID INT, Name VARCHAR(30), ContinentID INT, Population INT)
INSERT INTO @country (ID, Name, ContinentID, Population) VALUES (1, 'China', 1, 2000),(2, 'India', 1, 1500),(3, 'Ethiopia', 2, 7500),(4, 'United States', 3, 5000)
;WITH popRank AS (
SELECT ROW_NUMBER() OVER (PARTITION BY ct.ID ORDER BY POPULATION DESC) AS row, ct.name AS continentName, c.name AS countryName, c.population, c.ContinentID
FROM @country c
INNER JOIN @continent ct
ON c.ContinentID = ct.ID
SELECT r.countryName AS biggestPopCountry, r.population as biggestPopCount, r1.countryName AS lowestPopCountry, r1.population as lowestPopCount
FROM popRank r
INNER JOIN popRank r1
ON r.ContinentID = r1.ContinentID
AND r1.row = (SELECT MAX(row) FROM popRank WHERE ContinentID = r.ContinentID)
AND r.row = 1 -
How can I make a detailed form widget into TWO columns?
how can I make a detailed form widget into TWO columns? I have a contact form with a lot of fields.
Hi Whatsmyjam9999,
You can place a blank composition widget then click tigger 1, click inside target 1 and from menu--> files--> place the image and adjust it's dimensions, you can repeat the same steps for trigger 2 and 3
Here is a video link http://ghai2.worldsecuresystems.com/jing/2013-07-22_1442.swf -
Hi Friend.
I have to write two triggers on same table for auditing different columns of different users(may be different modules).
I will have an audit table in which i will insert data such as (user_id,module_id,column_name,old_col_val,new_col_val,timestamp)
Now different users from different modules will update the data on same table may be same columns from different front end forms!
If we write directly, we will not be able to know which column is updated by which user.
My question is in this case how can we control the triggers to raise differently?You can use WHEN clause to fire a trigger only when some condition is true - you can check an user also,
look at simple example:
- suposse we have two users US1 and US2:
C:\>sqlplus sys as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Pn Gru 6 13:14:22 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> create user us1 identified by us1;
User created.
SQL> create user us2 identified by us2;
User created.
SQL> grant connect, resource to us1, us2;
Grant succeeded.
SQL> grant create public synonym to us1, us2;
Grant succeeded.and suposse we have a table with three columns + audit table:
SQL> connect us1
Enter password:
Connected.
SQL> create table tab123(
2 col1 number,
3 col2 number,
4 col3 number);
Table created.
SQL> create table audit_tab123(
2 username varchar2(100),
3 col1 number,
4 col2 number,
5 col3 number );
Table created.
SQL> grant select, update, insert on tab123 to us2;
Grant succeeded.
SQL> grant select, update, insert on audit_tab123 to us2;
Grant succeeded.
SQL> create public synonym tab123 for tab123;
Synonym created.
SQL> insert into tab123 values( 1, 1, 1 );
1 row created.
SQL> commit;
Commit complete.We want a trigger that is fired only by user US1 and only after update of COL1 and COL2
(COL3 is ignored):
SQL> connect us1/us1
Connected.
SQL> CREATE OR REPLACE TRIGGER Trig_123_US1
2 AFTER UPDATE OF col1, col2 ON tab123
3 FOR EACH ROW
4 WHEN ( user = 'US1' )
5 BEGIN
6 INSERT INTO audit_tab123( username, col1, col2 )
7 VALUES( user, :new.col1, :new.col2 );
8 END;
SQL> /
Trigger created.And we want a second trigger that is fired only by user US2 and only after update of COL2 and COL3
(COL1 is ignored):
SQL> connect us1/us1
Connected.
SQL> CREATE OR REPLACE TRIGGER Trig_123_US2
2 AFTER UPDATE OF col2, col3 ON tab123
3 FOR EACH ROW
4 WHEN ( user = 'US2' )
5 BEGIN
6 INSERT INTO audit_tab123( username, col2, col3 )
7 VALUES( user, :new.col2, :new.col3 );
8 END;
9 /
Trigger created.and now let test our triggers:
SQL> connect us1/us1
Connected.
SQL> update tab123 set col1 = 22;
1 row updated.
SQL> update tab123 set col2 = 22;
1 row updated.
SQL> update tab123 set col3 = 22;
1 row updated.
SQL> commit;
Commit complete.
SQL> select * from audit_tab123;
USERNAME COL1 COL2 COL3
US1 22 1
US1 22 22
SQL> connect us2/us2
Connected.
SQL> update tab123 set col1 = 333;
1 row updated.
SQL> update tab123 set col2 = 333;
1 row updated.
SQL> update tab123 set col3 = 333;
1 row updated.
SQL> commit
2 ;
Commit complete.
SQL> select * from us1.audit_tab123;
USERNAME COL1 COL2 COL3
US1 22 1
US1 22 22
US2 333 22
US2 333 333As you see, each trigger is fired only once, first triger only for user US1 and columns COL1 and COL2,
and second trigger only for user US2 and only after update of COL2 and COL3.
I hope this will help. -
Select *, rowid into var1, var2 from...
Hello,
as mentioned in the subject, I want to do the following in plsql:
var1 table%rowtype;
var2 rowid;
select *, rowid into var1, var2 from table where ...;
So this is not possible yet, what else can I do instead as I ...
1. don't want to split one select statement into two.
2. don't know the columns of the table at compile time.
3. would like to use the rowtype, if possible.
Any ideas?
Thanx a lot
MatthiasIf you do not know the columns at compile-time then how is your update-statement working? Is that getting generated dynamically too? And are your updating all the columns in the table?
PS: Btw, you can declare a cursor and have a %rowtype variable based on that. Like this:
declare
cursor c1
is
select t.*,
t.rowid
from table1 t
r_cursor c1%rowtype;
begin
for r_cursor in c1
loop
dbms_output.put_line ( 'Col2: [' || r_cursor.col2 || ']' );
update table1
set col2 = r_cursor.col2 + 10
where table1.rowid = r_cursor.rowid
end loop;
end;
/ -
Splitting Data Already In A Column Into Separate Columns
Hi and I have a column of First Name & Last Name. I want to split them and put them into two columns. How do I do that without re-typing?
As I studied the menu of the 18 versions, I discovered "funny" things.
In localized versions we may have three wordings for the same item, one in Keynote, one in Numbers, one in Pages;
With the revisions of iWork '09, they introduced a menu item "Export" in the File menu.
Alas they failed to install it in Numbers localized versions.
The surprizing differences are numerous.
Some text attributes are available in Pages and Keynote, not in Numbers. Why, we may have text boxes in Numbers too. Just an exemple, Strikethrough is missing in the Format menu.
But the tracking menu offers 4 items in Numbers and only 3 in Pages ????
In the document Inspector, in Pages, we have check box + text field to rule footer or header. We have only text field in Numbers so we can't rule the documents the same.
I may understand that external cell references are unavailable in Pages but not why popup, stepper, slider and checkbox aren't.
They fixed a limit to the number of columns in a Pages's table.
I reported that it was annoying to import AW WP documents.
The limit no longer apply when we import but it continue to strike when we build a table by ourself.
As you see, I know that we are far from a perfect world.
Two days ago, I dropped a kind of bomb in the AppleScript forum when, after writing that AppleScript treats correctly the users speaking English and using mm/dd/yyyy dates but that others are 2nd class users, I concluded saying that, from my point of view it's a kind of apartheid.
Yvan KOENIG (VALLAURIS, France) mardi 8 septembre 2009 19:42:06 -
How to write two triggers on same table how it works?
Hello sir..
I have to write two triggers on same table for auditing different columns of different pages (may be different modules).
I will have an audit table in which i will insert data such as (user_id,module_id,column_name,old_col_val,new_col_ val,timestamp)
Now different users from different pages will update the data on same table may be same columns!
If we write directly, we will not be able to know which column is updated from different pages.
My question is how can we control the triggers to raise based on the pagesA trigger is executed whenever the table is inserted / updated / deleted (depend on trigger definition). It won't know what 'page' caused the operation. You can prepare a trigger for one page.
In order to fulfill your need, you need some way to tell the trigger where you are. There are many ways to accomplish this. Some possible methods are (please check the documents for detail)
DBMS_SESSION.SET_IDENTIFIER
DBMS_APPLICATION_INFO.SET_MODULEFor example, you can call DBMS_SESSION.SET_IDENTIFIER to set an ID from your page, and then call sys_context to read the ID back:
In Page:
exec dbms_session.set_identifier('Page1');
...In Trigger
pageid := sys_context('USERENV', 'CLIENT_IDENTIFIER') ;
...Note that if you use a connection pool, you may need to properly reset the session information before return, in order to avoid messing up the session information when the connection is used next time. -
How can I separate one column into multiple column?
How can I separate one column into multiple column?
This is what I have:
BUYER_ID ATTRIBUTE_NAME ATTRIBUTE_VALUE
0001 PHONE_NUMBER 555-555-0001
0001 EMAIL [email protected]
0001 CURRENCY USD
0002 PHONE_NUMBER 555-555-0002
0002 EMAIL [email protected]
0002 CURRENCY USD
0003 PHONE_NUMBER 555-555-0003
0003 EMAIL [email protected]
0003 CURRENCY CAD
This is what I would like to have:
BUYER_ID PHONE_NUMBER EMAIL CURRENCY
0001 555-555-0001 [email protected] USD
0002 555-555-0002 [email protected] USD
0003 555-555-0003 [email protected] CAD
Any help would be greatly appreciated.This is another solution. Suppose your actual table's name is test(which has the redundant data). create a table like this:
CREATE TABLE test2 (BUYER_ID number(10),PHONE_NUMBER varchar2(50),EMAIL varchar2(50),CURRENCY varchar2(50));
then you will type this procedure:
declare
phone_number_v varchar2(50);
EMAIL_v varchar2(50);
CURRENCY_v varchar2(50);
cursor my_test is select * from test;
begin
for my_test_curs in my_test loop
select ATTRIBUTE_VALUE INTO phone_number_v from test
where person_id=my_test_curs.person_id
and attribute_name ='PHONE_NUMBER';
select ATTRIBUTE_VALUE INTO EMAIL_v from test
where person_id=my_test_curs.person_id
and attribute_name ='EMAIL';
select ATTRIBUTE_VALUE INTO CURRENCY_v from test
where person_id=my_test_curs.person_id
and attribute_name ='CURRENCY';
INSERT INTO test2
VALUES (my_test_curs.person_id,phone_number_v,EMAIL_v,CURRENCY_v);
END LOOP;
END;
Then you will create your final table like this:
create table final_table as select * from test2 where 1=2;
After that write this code:
INSERT ALL
into final_table
SELECT DISTINCT(BUYER_ID),PHONE_NUMBER,EMAIL,CURRENCY
FROM TEST2;
If you have a huge amount of data in your original table this solution may take a long time to do what you need.
Maybe you are looking for
-
I created several text input fields in a presentation. A ghost image of the shortcut character displays when a user highlights the text field. Any insight??
-
Error while opening the external window
Hi I am trying to open an external window on click of a button. This is the piece of code I have written url = "http://www.google.com"; url = java.net.URLEncoder.encode( url ) ; String title="External Window"; //IWDWindow win=wdComponentAPI.getWindow
-
I saved my completed rendered video in Publish and Share as an MP4, but where is the file saved to. I set it to be saved on my desktop, but I don't see it. thanks
-
I need to change the display preferences very often. Is it possible to place only this one preference in the dock? Thanks.
-
Java.lang.IllegalStateException : output stream already retrived Error
Hi All I am trying to integrate crystal reports 10g with oracle 10g AS.My application works fine on TOMCAT 4.1.31,but when I depoly in oracle 10G AS,it shows the following exception Java.lang.IllegalStateException : output stream already retrived. An