Query Help Oracle [beginner]
HelloI want to display the records of these employees, whose qualities are between 2-4 by the EMP, Salgrade table of oracle... Schema Scott.
Help, please.
Select *.
from emp e, s salgrade
where e.sal > = s.losal and e.sal<>
and s.grade between 2 and 4
Tags: Database
Similar Questions
-
SQL Query for Oracle DB followed by using vCOPS
Hi guys,.
I installed a general SQL adapter to monitor an Oracle database in my environment. But I am not able to make it work there are a lot of problems in writing a SQL Quries. I work with one of the DBA and we are still not able to write the query to the right. Can someone give me an example of a query so that I can test it or tell me how to write the query to Oracle DB. Examples of files that are given under/samples/folder conf in the plug-in does not help us. So if someone has a link or if someone has it please help me with query files.
Thanks in advance
fix. the biggest challenge with the SQL adapter is to write the query in such a way the release of product that is easily consumable by vcops and maps directly to RESOURCEKIND and RESOURCENAME in vcops. The result can also be hierarchical for more efficiency, i.e.
metric
-submetric1
-submetric2
-
Hi all
How can I send a query to oracle using cfstoredprod?
Try this:
< datasource = "" #application.dsn # cfstoredproc "procedure =" #importTable #">"
< cfprocparam type = 'in' cfsqltype = "cf_sql_refcursor" value = "#myQuery #" >
< / cfstoredproc >
The Oracle code:
Procedure importTable (v_table IN SYS_REFCURSOR) is
Error: [Oracle JDBC Driver] impossible to determine the type of the specified object.
Any ideas?
Thanks in advance.
Get your drives and put them in a query object (if they aren't already), let's call it getRecs, and:
INSERT ALL INTO schema.tableName(columnA, columnB, columnC, etc) VALUES ( SELECT * FROM DUAL, , , ) You must include the "SELECT * FROM DUAL" after the loop to exit. Connect it to your database (Oracle), insert all the lines and disconnect. Place it in a CFTRANSACTION tag to make sure that they are all inserted or all cancelled.
HTH,
^_^
-
Convert the SQL query to Oracle
Hi all
I have two SQL queries to create the table.
Query1.
CREATE TABLE [dbo]. [DocumentType] (
[DocType] [varchar] (20) GATHER SQL_Latin1_General_CP1_CI_AS NOT NULL,.
[SubCat] [varchar] (20) GATHER SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo]. [DocumentType] ADD
CONSTRAINT [PK_DocumentType] PRIMARY KEY CLUSTER
(
[DocType],
[SubCat]) ON [PRIMARY]
Query2.
CREATE TABLE [dbo]. [SBU] (
[SBU] [varchar] (51) GATHER SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo]. [SBU] ADD
[PK_SBU] CLUSTERED PRIMARY KEY CONSTRAINT
(
[SBU]
) ON [PRIMARY]
What will be the query in Oracle?
Please suggest!
Kind regards
ShahQuery1.
CREATE TABLE dbo. DocumentType)
DocType varchar2 (20) NOT NULL,
SubCat varchar (20) NOT NULL,
CONSTRAINT PK_DocumentType PRIMARY KEY (DocType, SubCat)
)
/Query2.
CREATE TABLE dbo. SBU)
SBU varchar2 (51),
CONSTRAINT PK_SBU PRIMARY KEY (UDF)
)
/It is useful for you?
Published by: insa on June 12, 2012 22:42
-
Hierarchical Oracle query help needed - path between the crux of two brothers and sisters
I want to find the path between two nodes of oracle hierarchical Table.
Consider the following case-
NodeId - ParentId
=============
1 > > > > > > 0
2 > > > > > > 1
3 > > > > > > 2
4 > > > > > > 3
5 > > > > > > 0
6 > > > > > > 5
Here I want to query the database table that if there is a path between nodes 3 and 5?
The previous query you provided work upwards to the root node.
Here is my expected result, 3-> 2-> 1-> 0-> 5
Yet once if I have a query in the table to get the path between 1 and 3, I want to get out of the way - next
1-> 2-> 3
Therefore, the query works in both cases. Where ADI root can act as an intermediate or no node.
Can you please guide me how I can get it?
Thank you.Hello
user13276471 wrote:
I want to find the path between two nodes of oracle hierarchical Table.Consider the following case-
NodeId - ParentId
=============
1 >>>>>> 0
2 >>>>>> 1
3 >>>>>> 2
4 >>>>>> 3
5 >>>>>> 0
6 >>>>>> 5
Here I want to query the database table that if there is a path between nodes 3 and 5?
The previous queryWhat application is this? If you're referering to another thread, then post a link, such as {message identifier: = 10769125}
you provided work upwards to the root node.
Here is my expected result, 3--> 2--> 1--> 0--> 5
Yet once if I have a query in the table to get the path between 1 and 3, I want to get out of the way - next
1--> 2--> 3Therefore, the query works in both cases. Where ADI root can act as an intermediate or no node.
Can you please guide me how I can get it?
I think you want something like this:
WITH bottom_up_from_src AS ( SELECT nodeid , parentid FROM table_x START WITH nodeid = :src_nodeid CONNECT BY nodeid = PRIOR parentid ) , bottom_up_from_dst AS ( SELECT * FROM bottom_up_from_src UNION ALL SELECT parentid AS nodeid , nodeid AS parentid FROM table_x WHERE nodeid NOT IN ( SELECT nodeid FROM bottom_up_from_src ) START WITH nodeid = :dst_nodeid CONNECT BY nodeid = PRIOR parentid ) SELECT :src_nodeid || SYS_CONNECT_BY_PATH (parentid, '-->') AS display_path FROM bottom_up_from_dst WHERE parentid = :dst_nodeid START WITH nodeid = :src_nodeid CONNECT BY nodeid = PRIOR parentid ;
This will show how you can get it from: src_nodeid at dst_nodeid, moving to the top or to the bottom of a hierarchy at a time step. This will work regardless of the fact that
- : src_nodeid is the ancestor of the: dst_nodeid, or
- : src_nodeid is a descendant of: dst_nodeid, or
- both: src_nodeid and: dst_nodeid are the descendants of another node (e.g. 0).
- : src_nodeid is the ancestor of the: dst_nodeid, or
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0). It is always important, but particularly so with CONNECT BY queries, because each version since Oracle 7 had significant improvements in this area.
See the FAQ forum {message identifier: = 9360002}
Hierarchical query help need to Oracle
HelloI'm in a deep trouble.
I want to do a hierarchical query in my TreeView table in oracle. But I want that the query retrieves information path between two nodes.
Review the table below.
------------------------------------------------------
Node ID | Name of the node. ID of the parent
-----------------------------------------------------
1A 0
2 1
3C0
4 2
-----------------------------------------------------
What I want is that I'll give you 2 node id in the request. One is the source node and the other is the destination node.
so if I put 1 node and node 4, I want to be the output
1-> 2-> 4
I want just a return line. Or there may be several rows but stands only the node of this path.
1
2
4
----
This means that I don't want to node 3 in the search result.
More if I have the source as 4 node and the node of destination as 1 then I will also get an output of the query as below-
4-> 2-> 1
This means that the search for the query for the result in a way directional bi.
If anyone can give me some information about who it's going to be great for me.
Published by: user13276471 on December 31, 2012 03:21
Hello
Welcome to the forum!
Assuming you have 2 separate nodes: Node_A and: node_b, you can find the hierarchy from one to the other like this:
SELECT SYS_CONNECT_BY_PATH (node_id, ',') AS lineage
FROM table_x
WHERE node_id IN (:node_a, :node_b)
AND LEVEL > 1
START WITH node_id IN (:node_a, :node_b)
CONNECT BY parent_id = PRIOR node_id
;
It will work if: the Node_A is an ancestor of the: node_b, or if: node_b is an ancestor of the: Node_A.
If is the ancestor of the other, then it will produce 0 rows.
Oracle beginner here... need help with login
HelloI just installed oracle 11g... and I opened the SQL more appplication...
It requires a username and password... I have not yet created the user...
Wat do I do? .. How to connect?
Or y at - it accounts to predefined by the user in oracle? Pls help...
Hello
What is the o/s?
There are indeed predefined users that will be created if you select the option to create. Other that those users who are optional, there are 2 users will be created with the installation of the database, Sys and System. Try to connect as follows,
sqlplus / as sysdba
This should connect as user Sys and you can do your work.
HTH
Aman...
Hi all
I have the order by clause and the Description field gets data
like (shipping) and (shipping - Volumes traded) , but the
InStr, function cannot tell the difference between them and can not get good results
order by
DECODE (instr (Description, 'Shipping costs', 1), 1, 1, 3),
DECODE (instr (Description, ' delivery charges for ', 1), 1.2, 3).
DECODE (instr ("Description, ' delivery charges - the Volumes traded", 1), 1, 3, 3)
any help how to solve this problem
I expect results like this in order to
1 delivery charge
Delivery 2 to
3 delivery - traded volumes
example 1
1 delivery charge
Delivery 2 to
3 delivery - traded volumes
but my performance varies and I get
3 delivery - traded volumes
1 delivery charge
Delivery 2 to
example 2
1 delivery charge
Delivery charges 2 - traded volumes
My varies and I get
Delivery charges 2 - traded volumes
1 delivery charge
Hello
Your use of INSTR assumes that the string "delivery fees" always appears at the beginning of the string (INSTR returns 1 because that is where the search string is found to start)... Baring all in mind...
WITH the list in the FORM (SELECT "delivery Charge #1" ") | Description OF the dual UNION ALL | |
SELECT "delivery fees". | Double UNION ALL | |
SELECT "shipping for. | Double UNION ALL | |
SELECT "shipping costs - negotiated Volumes." | Double UNION ALL | |
SELECT "Shipping A in the beginning" | Double UNION ALL | |
SELECT 'delivery charges against '. | OF the double | |
) |
SELECT description
LIST
In case of ORDERS description WHEN = "delivery charges - the Volumes negotiated" THEN 3
Description WHEN AS "shipping costs for %. | THEN 2 | |
Description WHEN = "delivery fees". | THEN 1 | |
ANOTHER 99 | ||
END; |
DESCRIPTION
--------------------------------
Delivery charges
Delivery charges for
Delivery charges - traded Volumes
Delivery charges against
A delivery charge, not at the beginning
Delivery #1
6 selected lines.
See you soon,.
Gas
SQL query help in oracle database 11g
I have test table name these data and column as
Select t.user_id, t.user_date, t.amount
t-test
----------------------------------------------------------
User_id date amount
10 1/1 / 2011 10
20/1 2/11/2011
11 1/3 / 2011 30
40/2 10/2/2011
You want to display data in this format...
User_id date amount here is the logic how to get the amount
1 10/1/2011 10 10
11 1/2 / 2011 30 10 + 20
11 1/3 / 2011 60 (10 + 20) + 30
2 10/2/2011 40 40
SELECT | t.user_id, t.user_date, t.amount | |
, | SUM (t.amount) OVER (PARTITION BY t.user_id |
ORDER BY | t.user_date |
) AS the amount | ||
Of | t-test |
ORDER BY t.user_id |
, | t.user_date |
; |
NOT THOUSANDS IN *.
3600 *.
2900 *.
2500 *.
4000 *.
3200 *.
SAL should come in the stars.
Please guide me on how to solve this problem.
Ref:
Replacement of number of asterisk
annual salaries with asterisks
Oracle 11g Release 2
Frank Kulash was able to help on this issue yesterday. But I got additional requirements. Details below.
CASE 1:
create table t
(key primary id number,)
supplier_id number,
number of supplier_desc_id
batch number,
date of dt_recv
)
/
Insert into t
values (35405,605,3809,0,TO_DATE('14-JUN-2013','DD-MON-yyyy')
/
Insert into t
values (58543,605,3809,0,TO_DATE('10-DEC-2013','DD-MON-yyyy')
/
Insert into t
values (136793,605,3809,1,TO_DATE('11-NOV-2014','DD-MON-yyyy')
/
Insert into t
values (96510,605,3809,1,TO_DATE('11-JUN-2014','DD-MON-yyyy')
/
Insert into t
values (94222,605,3809,1,TO_DATE('09-MAY-2014','DD-MON-yyyy')
/
Insert into t
values (108229,605,3809,3,TO_DATE('09-SEP-2014','DD-MON-yyyy')
/
Insert into t
values (114585,605,3809,2,TO_DATE('28-OCT-2014','DD-MON-yyyy')
/
commit;
Select * from t;
ID SUPPLIER_ID SUPPLIER_DESC_ID BATCH DT_RECV
---------- ----------- ------------------------ ----------------- -------------
35405 605 3809 0 14 JUNE 2013
58543 605 3809 0 10 DECEMBER 2013
3809 605 136793 1 11 NOVEMBER 2014
96510 605 3809 1 10 JUNE 2014
94222 605 3809 1 9 MAY 2014
108229 605 3809 3 09 - SEP - 2014
114585 605 3809 2 28 OCTOBER 2014
RULE: when there are 2 or more records with batch = 1, return the two most
recent recordings with batch = 1 AND any recording (no matter the batch) that
has a DT_RECV > = only the DT_RECV of the 2nd record most of batch = 1 (June 10, 2014)
96510 10 June 2014 (2nd most active record with batch = 1)
136793 11 November 2014 (more current label with batch = 1)
94222 may 9, 2014 (not interested in this matter, since it is greater than 2 versions)
The results should be:
ID SUPPLIER_ID SUPPLIER_DESC_ID STATUS_ID DT_RECV ---------- ----------- ------------------------ ----------------- ------------- 96510 605 3809 1 10-JUN-2014 136793 605 3809 1 11-NOV-2014 114585 605 3809 2 28-OCT-2014 >= 10-JUN-2014 108229 605 3809 3 09-SEP-2014 >= 10-JUN-2014 This query returns the correct results: WITH got_r_num AS ( SELECT id, supplier_id, supplier_desc_id, status_id, dt_recv , ROW_NUMBER () OVER ( PARTITION BY supplier_id,supplier_desc_id,status_id ORDER BY dt_recv DESC ) AS r_num FROM t ) , got_dt_cutoff AS ( SELECT id, supplier_id, supplier_desc_id, status_id, dt_recv , MIN ( CASE WHEN status_id = 1 AND r_num <= 2 THEN dt_recv END ) OVER (PARTITIN BY supplier_id,supplier_desc_id) AS dt_cutoff FROM got_r_num ) SELECT id, supplier_id, supplier_desc_id, status_id, dt_recv FROM got_dt_cutoff WHERE dt_recv >= dt_cutoff ORDER BY dt_recv ; NOTE: records are grouped by supplier_id/supplier_desc_id
CASE 2:
truncate table t; insert into table t values(45401,801300,4466,0,TO_DATE('21-AUG-2013','DD-MON-YYYY') / insert into table t values(44414,801300,4466,0,TO_DATE('08-AUG-2013','DD-MON-YYYY') / commit ; select * from t; CONTENT_ID SUPPLIER_ID SUPPLIER_CONTENT_DESC_ID CONTENT_STATUS_ID RECEIVE_DATE ---------- ----------- ------------------------ ----------------- ------------ 451 801300 4466 0 21-AUG-2013 44414 801300 4466 0 08-AUG-2013 801300 4466 0 08-AUG-2013
RULE: when there is no batch = 1, then return all rows
The query above does not work for this case.
CASE 3:
truncate table t; insert into table t values(29887,609051,1781,0,TO_DATE('19-APR-2013','DD-MON-YYYY') / insert into table t values(33623,609051,1781,0,TO_DATE('24-MAY-2013','DD-MON-YYYY') / insert into table t values(45477,609051,1781,0,TO_DATE('22-AUG-2013','DD-MON-YYYY') / insert into table t values(54013,609051,1781,1,TO_DATE('22-OCT-2013','DD-MON-YYYY') / commit; select * from t; CONTENT_ID SUPPLIER_ID SUPPLIER_CONTENT_DESC_ID CONTENT_STATUS_ID RECEIVE_DATE ---------- ----------- ------------------------ ----------------- ------------- 29887 609051 1781 0 19-APR-2013 33623 609051 1781 0 24-MAY-2013 45477 609051 1781 0 22-AUG-2013 54013 609051 1781 1 22-OCT-2013
RULE: When there is only to record with batch = 1, return all rows
The query above does not work for this case.
Hello
orclrunner wrote:
Oracle 11g Release 2
Frank Kulash was able to help on this issue yesterday. But I got additional requirements. Details below.
CASE 1:
create table t
(key primary id number,)
supplier_id number,
number of supplier_desc_id
batch number,
date of dt_recv
)
/
Insert into t
values (35405,605,3809,0,TO_DATE('14-JUN-2013','DD-MON-yyyy')
/
Insert into t
values (58543,605,3809,0,TO_DATE('10-DEC-2013','DD-MON-yyyy')
/
Insert into t
values (136793,605,3809,1,TO_DATE('11-NOV-2014','DD-MON-yyyy')
/
Insert into t
values (96510,605,3809,1,TO_DATE('11-JUN-2014','DD-MON-yyyy')
/
Insert into t
values (94222,605,3809,1,TO_DATE('09-MAY-2014','DD-MON-yyyy')
/
Insert into t
values (108229,605,3809,3,TO_DATE('09-SEP-2014','DD-MON-yyyy')
/
Insert into t
values (114585,605,3809,2,TO_DATE('28-OCT-2014','DD-MON-yyyy')
/
commit;
Select * from t;
ID SUPPLIER_ID SUPPLIER_DESC_ID BATCH DT_RECV
---------- ----------- ------------------------ ----------------- -------------
35405 605 3809 0 14 JUNE 2013
58543 605 3809 0 10 DECEMBER 2013
3809 605 136793 1 11 NOVEMBER 2014
96510 605 3809 1 10 JUNE 2014
94222 605 3809 1 9 MAY 2014
108229 605 3809 3 09 - SEP - 2014
114585 605 3809 2 28 OCTOBER 2014
RULE: when there are 2 or more records with batch = 1, return the two most
recent recordings with batch = 1 AND any recording (no matter the batch) that
has a DT_RECV > = only the DT_RECV of the 2nd record most of batch = 1 (June 10, 2014)
96510 10 June 2014 (2nd most active record with batch = 1)
136793 11 November 2014 (more current label with batch = 1)
94222 may 9, 2014 (not interested in this matter, since it is greater than 2 versions)
The results should be:
- ID SUPPLIER_ID SUPPLIER_DESC_ID BATCH DT_RECV
- ---------- ----------- ------------------------ ----------------- -------------
- 96510 605 3809 1 10 JUNE 2014
- 3809 605 136793 1 11 NOVEMBER 2014
- 114585 605 3809 2 28 OCTOBER 2014 > = JUNE 10, 2014
- 108229 605 3809 3 09 - SEP - 2014 > = JUNE 10, 2014
- This query returns the correct results:
- WITH got_r_num AS
- (
- SELECT id, supplier_id, supplier_desc_id, batch, dt_recv
- , ROW_NUMBER () OVER (PARTITION BY supplier_id, supplier_desc_id, batch)
- ORDER BY dt_recv DESC
- ) AS r_num
- T
- )
- got_dt_cutoff AS
- (
- SELECT id, supplier_id, supplier_desc_id, batch, dt_recv
- MIN (CASE
- WHEN batch = 1
- AND r_num<=>=>
- THEN dt_recv
- END
- ) ON (PARTITIN BY supplier_id, supplier_desc_id) AS dt_cutoff
- OF got_r_num
- )
- SELECT id, supplier_id, supplier_desc_id, batch, dt_recv
- OF got_dt_cutoff
- WHERE dt_recv > = dt_cutoff
- ORDER BY dt_recv
- ;
- NOTE: the records are grouped by supplier_id/supplier_desc_id
CASE 2:
- truncate table t;
- insert into table t
- values (45401,801300,4466,0,to_date('21-Aug-2013','DD-mon-YYYY')
- /
- insert into table t
- values (44414,801300,4466,0,to_date('08-Aug-2013','DD-mon-YYYY')
- /
- commit;
- Select * from t;
- CONTENT_ID SUPPLIER_ID SUPPLIER_CONTENT_DESC_ID CONTENT_STATUS_ID RECEIVE_DATE
- ---------- ----------- ------------------------ ----------------- ------------
- 451 801300 4466 0 21 AUGUST 2013
- 44414 801300 4466 0 AUGUST 8, 2013
- 801300 4466 0 AUGUST 8, 2013
RULE: when there is no batch = 1, then return all rows
The query above does not work for this case.
CASE 3:
- truncate table t;
- insert into table t
- values (29887,609051,1781,0,to_date('19-Apr-2013','DD-mon-YYYY')
- /
- insert into table t
- values (33623,609051,1781,0,to_date('24-May-2013','DD-mon-YYYY')
- /
- insert into table t
- values (45477,609051,1781,0,to_date('22-Aug-2013','DD-mon-YYYY')
- /
- insert into table t
- values (54013,609051,1781,1,to_date('22-Oct-2013','DD-mon-YYYY')
- /
- commit;
- Select * from t;
- CONTENT_ID SUPPLIER_ID SUPPLIER_CONTENT_DESC_ID CONTENT_STATUS_ID RECEIVE_DATE
- ---------- ----------- ------------------------ ----------------- -------------
- 29887 609051 1781 0 19 APRIL 2013
- 33623 609051 1781 0 24 MAY 2013
- 45477 609051 1781 0 22 AUGUST 2013
- 54013 609051 1781 1 22 OCTOBER 2013
RULE: When there is only to record with batch = 1, return all rows
The query above does not work for this case.
Want to get answers that work, or is it possible to get responses that cause errors?
Make sure that the INSERT statements you post too much work. Test (and, if necessary, correct) them before posting. All the instructions insert above have errors.
The query above (once you correct the spelling of PARTITION) returns all the lines after a date limit. It's always what you want, only the details of how calculated this date limit changed. In accordance with the new requirements, the closing date must be earlier than the actual lines dt_recv in there are not 2 (or more) with batch = 1 for any combination of (supplier_id, supplier_desc_id). All you have to do is change "r_num".<= 2"="" to="" "r_num="2" ,"="" when="" computing="" dt_cutoff,="" and="" return="" an="" impossiblly="" early="" date="" if="" there="" is="" no="" such="" row. ="" (i="" assume="" that="" dt_recv="" can="" not="" be="">=>
WITH got_r_num AS
(
SELECT id, supplier_id, supplier_desc_id, batch, dt_recv
ROW_NUMBER () OVER (PARTITION BY supplier_id
supplier_desc_id
batch
ORDER BY dt_recv DESC
) AS r_num
T
)
got_dt_cutoff AS
(
SELECT id, supplier_id, supplier_desc_id, batch, dt_recv
, NVL ( MIN (CASE)
WHEN batch = 1
AND = 2 r_num - not <=, as="">=,>
THEN dt_recv
END
) OVER (PARTITION BY supplier_id
supplier_desc_id
)
, TO_DATE ('1', 'J') - first DATE in Oracle
( ) AS dt_cutoff
OF got_r_num
)
SELECT id, supplier_id, supplier_desc_id, batch, dt_recv
OF got_dt_cutoff
WHERE dt_recv > = dt_cutoff
ORDER BY supplier_id
supplier_desc_id
dt_recv
;
If dt_recv can be NULL, it is a bit more complicated, but only a little. Post instructions INSERT (work) and outcomes if you would like to help with this scenario.
convert the access query to oracle sql
I'm trying to convert this query MS Access to oracle sql:
Sum (IIf (IsNull ([INV_MTL_MATERIAL_TRANSACTIONS1]! [PRIMARY_QUANTITY]), 0,-[INV_MTL_MATERIAL_TRANSACTIONS1]! [PRIMARY_QUANTITY])) AS PRIMARY_QTY
I tried to convert myself but still no luck. Invalid number of arguments.
Sum (if (NVL (INV. MTL_MATERIAL_TRANSACTIONS1. PRIMARY_QUANTITY), 0,-INV. MTL_MATERIAL_TRANSACTIONS1. PRIMARY_QUANTITY)) AS PRIMARY_QTY
Can someone help me convert this request? Thank you.
The immediate if (IIF) statement said:
If primary_quantity is null return 0 for another return negative primary_quantity.
Since there is no difference at all between 0 and - 0 I would write it as:
sum (nvl (primary_quantity, 0) * - 1).
Change a minute later, never send before thinking.
Because you are just adding up the values obtained, he must not care about NULL values at all as aggregate functions generally ignore nulls, it should just be:
Sum (primary_quantity * - 1).
John
need help on creating pivot query
SELECT * FROM TEST1
----------------
VALUE OF PERSON COMPUTERNAME
COMP1 ABC 3
COMP2 ABC 5
COMP1 CAD 3
COMP3 CAD 5
COMP2 TES 1
COMP1 TES 5
COMP3 ABC 2
myQuery
----------------------------
Select the link null, label, value1 COUNT (VALUE)
from 'test1 '.
CONTROL group PER PERSON
Results
---------
Link label value1
- ABC 3
- CAD 2
- TES 2
My requirement
---------------
can we have something like that out using the concept of pivot? If so can you share an example query pls.
Link label value1
-ABC ORDI1, COMP2, COMP3
-CAD COMP1, COMP2
-YOUR ORDI1, COMP3
Hello
Subhash C-Oracle wrote:
need help on creating pivot query
SELECT * FROM TEST1
----------------
VALUE OF PERSON COMPUTERNAME
COMP1 ABC 3
COMP2 ABC 5
COMP1 CAD 3
COMP3 CAD 5
COMP2 TES 1
COMP1 TES 5
COMP3 ABC 2
myQuery
----------------------------
Select the link null, label, value1 COUNT (VALUE)
from 'test1 '.
CONTROL group PER PERSON
Results
---------
Link label value1
- ABC 3
- CAD 2
- TES 2
My requirement
---------------
can we have something like that out using the concept of pivot? If so can you share an example query pls.
Link label value1
-ABC ORDI1, COMP2, COMP3
-CAD COMP1, COMP2
-YOUR ORDI1, COMP3
This sounds like a job for LISTAGG:
SELECT NULL AS link
label
LISTAGG (comp_name, ',')
THE Group (ORDER BY ComputerName) AS value1
OF test1
GROUP BY label
;
If you would care to post CREATE TABLE and INSERT statements for your sample data, then I could test it.
Are you sure that the results you posted are what you want from data provided?
Is of the order of the elements in a significant list? In other words, when you say you want to get the results:
COMP1, COMP2
you'd be just as happy with
ORDI1, COMP2
? If the order is important, explains what this order.
SQL Query Help (not working not properly)
Hello everyone,
I use JDeveloper 12.1.2.0.0. I do a two-way communication using 3 tables, with links between them (and using schema HR).
In my example, I have something like:
Departments, employees, and the SalaryByJobs (I created this table where it shows a departmentd id, employee id, salary).
Whenever I click on one OR more departments, the employees up-to-date table by putting on the table, employees who belong to the selected department and the salaryByjob to put the jobs of the employees selected on the employees table.
So it's something like this:
The departments selected-> employees selected-> salarybyjbobs of these employees.
My query used (in the view) has the following code:
SELECT Employees.COMMISSION_PCT,
Employees.DEPARTMENT_ID,
Employees.EMAIL,
Employees.EMPLOYEE_ID,
Employees.FIRST_NAME,
Employees.HIRE_DATE,
Employees.JOB_ID,
Employees.LAST_NAME,
Employees.MANAGER_ID,
Employees.PHONE_NUMBER,
Employees.SALARY
Employees EMPLOYEES
WHERE (department_id IN (select * from THE (select cast (in_list(:variavel3) as mytableType) double) a))
Since I use the links, the employees table does not show anything at the beginning, so I added this to my query used to go: OR nvl(:variavel3,0) = 0
But now, whenever I try to select multiple lines, it gives me the invalid numbers and I don't understand why...
It's only one line of code and it is not in the bean.
Can someone help me?
PS - The bean will Department by Department, adds the departments with ',' and for each Department, gets employees who belongs to them.
My best regards,
Frederico Barracha.
The expression NVL (: variavel3, 0) = 0 is not correct. The data type of the return value of the NVL function is considered to be equal to the data type of the argument of 1 (that is, the data type of the variable binding: variavel3). You said that this variable contained a list separated by commas to ID, so the data type of the variable is VARCHAR2. As long as you compare the NVL expression of a number, you get 'Invalid number' exception, because Oracle expects a numeric data type on the left side of the comparison operator.
To avoid the exception "Invalid number", you can modify the expression by using one of the following options:
: variavel3 IS NULL
NVL (: variavel3, ' *') = ' *'
NVL (: variavel3, ' 0') = '0'
Option 1, so the simplest and clearest.
Dimitar
Column1 Column2 Column3
Tier1 Group1 1
Tier1 Group1 2
Group level 1 2 3
Tier1 Group2 4
Group level 1 3 5
Level 1 Group 3 6
Expected result:
Column1 Column2 Column3
Tier1 Group1 1
2
2 3 Group
4
3 5 group
6
Thanks for your help
Hello
Your front end that can probably not for you.
In SQL * Plus, for example:
BREAK ON column1 ON column2
SELECT column1, column2, column3
FROM table_x
ORDER BY column3
;
If you havd do in SQL, here's one way:
SELECT CASE
WHEN ROW_NUMBER () OVER ( PARTITION BY column1
ORDER BY column3
) = 1
THEN column1
END AS col1
, CASE
WHEN ROW_NUMBER () OVER ( PARTITION BY column2
ORDER BY column3
) = 1
THEN column1
, END AS col2
, column3
FROM table_x
ORDER BY column3
;
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Highlight a few places where the queries above are getting incorrect results and explain, using specific examples, how you get the results of the data provided in these places.
Always tell what version of Oracle you are using.
Published by: Frank Kulash, March 21, 2012 16:15
Maybe you are looking for
-
Can I share pictures and videos via Bluetooth to an android device?
mini iPad - 12.7 GB capacity I can't find a Bluetooth icon when I click the button share. And I can't share a photo from an even android device with a paired device. It is a problem for Apple in Myanmar because the internet connection is not very goo
-
Failed with unknown error 80070490 Windows Update
Update Windows guard fails with unknown error 80070490 when trying to install to install the important updates made automatically by Windows Update. Having this problem since February 10
-
The Officejet 4500 wireless printer can work wireless with a Wireless N Router?
My Officejet 4500 Wireless printer worked fine with my router wireless of the B of aging, but when the latter died, I replaced it with a Wireless N router, the 4500 is possible to work with the N Wireless neworking Protocol? Thanks for your help.
-
Dell CCTK reference - password clear hard drive without prompting
Hello I'm going to erase the password hard drive with the following command: CCTK - hddpwd = - valhddpwd = PASSWORD After restarting the client, I get a prompt if I change oder ignore the previous command. I need a solution to clear the password of H
-
Adding file to a jpeg file information affects quality?
If I add only some info file to a JPEG (no photo editing), it alters the quality of the picture? As if I put only in a description for the file of information on... Photoshop will understand that I changed only the information about the file and not