Help - lines of the columns in the query
I have table-CREATE TABLE group_device
(group_id NUMBER (8) NON NULL
member_id NUMBER (4) NOT NULL
device_id NUMBER (10) NOT NULL
, install_date DATE NOT NULL
remove_date DATE
);
INSERT INTO group_device (group_id, member_id, device_id, install_date, remove_date) VALUES (10, 1, 123, TO_DATE (May 23, 2012 "," mm/dd/yyyy"), TO_DATE (May 28, 2012","mm/dd/yyyy"));
INSERT INTO group_device (group_id, member_id, device_id, install_date, remove_date) VALUES (10, 1, 456, TO_DATE (May 28, 2012 "," mm/dd/yyyy"), TO_DATE (June 1, 2012","mm/dd/yyyy"));
INSERT INTO group_device (group_id, member_id, device_id, install_date, remove_date) VALUES (10, 1, 789, TO_DATE (June 1, 2012 "," mm/dd/yyyy"), null);
INSERT INTO group_device (group_id, member_id, device_id, install_date, remove_date) VALUES (10, 2, 999, TO_DATE (May 4, 2012 "," mm/dd/yyyy"), TO_DATE (May 17, 2012","mm/dd/yyyy"));
INSERT INTO group_device (group_id, member_id, device_id, install_date, remove_date) VALUES (10, 4, 1123, TO_DATE (January 22, 2012 "," mm/dd/yyyy"), TO_DATE (January 27, 2012","mm/dd/yyyy"));
INSERT INTO group_device (group_id, member_id, device_id, install_date, remove_date) VALUES (10, 4, 1456, TO_DATE (January 27, 2012 "," mm/dd/yyyy"), TO_DATE (January 28, 2012","mm/dd/yyyy"));
commit;
Select * from group_device;
Current output does look like in below
10 1 123 23 MAY 12 28 MAY 12
10 1 456 28 MAY 12 1ST JUNE 12
10 1 789 1 JUNE 12
10 2 999 4 MAY 12 MAY 17, 12
10 4 1123 22 JANUARY 12 JANUARY 27, 12
10 4 1456 27 JANUARY 12 28 JANUARY 12
Device_id - Replaced_device_id - remove_date: for group_id = 10
for example, if member_id = 1, device_id = 123A replaced by device_id = 456 on 28 May 12
DEVICE_ID = 456 was replaced by device_id = 789 on June 1, 12
If the output should look like this
10 123 456 28 May 12 - replaced
10 456 789 1 June 12 - replaced
10 789 - active
Similarly there are many groups, so it should list group_id based on
Thank you
That match your desired output?
select a.group_id, a.device_id, a.rep_device_id, a.rep_date, decode(NVL(a.rep_device_id, -1), -1, 'ACTIVE', 'REPLACED') rep_active
from (
select group_id, device_id, lead(device_id) over (partition by member_id order by install_date) rep_device_id,
lead(install_date) over (partition by member_id order by install_date) rep_date
from group_device
) a;
GROUP_ID DEVICE_ID REP_DEVICE_ID REP_DATE REP_ACTIVE
-------- ---------- ------------- --------- ----------
10 123 456 28-MAY-12 REPLACED
10 456 789 01-JUN-12 REPLACED
10 789 ACTIVE
10 999 ACTIVE
10 1123 1456 27-JAN-12 REPLACED
10 1456 ACTIVE
6 rows selected
Oracle 11g is not a version. Therefore, please do not forget to post the output of
select * from v$version;
Tags: Database
Similar Questions
-
Need help in the design of the structure of the table with the lines of the query
Hello
Need to design a page
ex:
Select empno, emp wage; is my query and returns two columns and four rows
the four rows should be my values in the structure of the table.
EmpNo - salary
---------------------
1 - 1000
-----------------------
2 - 2000
------------------------
3 - 3000
----------------------
4 - 4000
Kind regards
KrishnaHello
One of the ways is to create 2 RowLayouts dynamically like this
Row1-> Cell1--> HeaderRegion--> StaticStyleText (EMPNO attribute)
Row2-> Cell1--> StaticStyleText (EMPNO attribute) Cell2--> StaticStyleText (SALARYattribute)and iterate this code for all the lines of the vo.
Kind regards
Mukesh Uchaniya -
Need help to highlight the query text in the document
Hi, I'm trying to load files into the blob column and try to create the text index.
I need to query the blob column in the original glass by a string, which should return the relevant documents with the query string, highlighted with some color.
Can you please help me with an example of the above.
Thanks in advance.SCOTT@orcl_11gR2> -- table: SCOTT@orcl_11gR2> CREATE TABLE document_tab 2 (document_col BLOB) 3 / Table created. SCOTT@orcl_11gR2> -- procedure to load documents: SCOTT@orcl_11gR2> CREATE OR REPLACE PROCEDURE load_document 2 (p_dir IN VARCHAR2, 3 p_file IN VARCHAR2) 4 AS 5 v_blob BLOB; 6 v_bfile BFILE; 7 BEGIN 8 INSERT INTO document_tab (document_col) 9 VALUES (EMPTY_BLOB()) 10 RETURNING document_col INTO v_blob; 11 v_bfile := BFILENAME (UPPER (p_dir), p_file); 12 DBMS_LOB.FILEOPEN (v_bfile, DBMS_LOB.LOB_READONLY); 13 DBMS_LOB.LOADFROMFILE (v_blob, v_bfile, DBMS_LOB.GETLENGTH (v_bfile)); 14 DBMS_LOB.FILECLOSE (v_bfile); 15 END load_document; 16 / Procedure created. SCOTT@orcl_11gR2> SHOW ERRORS No errors. SCOTT@orcl_11gR2> -- load documents (directory and files must be on server, not client): SCOTT@orcl_11gR2> CREATE OR REPLACE DIRECTORY my_dir AS 'c:\my_oracle_files' 2 / Directory created. SCOTT@orcl_11gR2> BEGIN 2 load_document ('my_dir', 'banana.pdf'); 3 load_document ('my_dir', 'english.doc'); 4 load_document ('my_dir', 'sample.txt'); 5 END; 6 / PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> -- confirm files were loaded: SCOTT@orcl_11gR2> SELECT DBMS_LOB.GETLENGTH (document_col) 2 FROM document_tab 3 / DBMS_LOB.GETLENGTH(DOCUMENT_COL) -------------------------------- 222824 22016 60 3 rows selected. SCOTT@orcl_11gR2> -- text index: SCOTT@orcl_11gR2> CREATE INDEX document_idx 2 ON document_tab (document_col) 3 INDEXTYPE IS CTXSYS.CONTEXT 4 / Index created. SCOTT@orcl_11gR2> -- confirm files were indexed: SCOTT@orcl_11gR2> SELECT COUNT(*) FROM dr$document_idx$i 2 / COUNT(*) ---------- 319 1 row selected. SCOTT@orcl_11gR2> -- function to return highlighted document: SCOTT@orcl_11gR2> CREATE OR REPLACE FUNCTION your_markup 2 (p_index_name IN VARCHAR2, 3 p_textkey IN VARCHAR2, 4 p_text_query IN VARCHAR2, 5 p_plaintext IN BOOLEAN DEFAULT TRUE, 6 p_tagset IN VARCHAR2 DEFAULT 'HTML_DEFAULT', 7 p_starttag IN VARCHAR2 DEFAULT '*', 8 p_endtag IN VARCHAR2 DEFAULT '*', 9 p_key_type IN VARCHAR2 DEFAULT 'ROWID') 10 RETURN CLOB 11 AS 12 v_clob CLOB; 13 BEGIN 14 CTX_DOC.SET_KEY_TYPE (p_key_type); 15 CTX_DOC.MARKUP 16 (index_name => p_index_name, 17 textkey => p_textkey, 18 text_query => p_text_query, 19 restab => v_clob, 20 plaintext => p_plaintext, 21 tagset => p_tagset, 22 starttag => p_starttag, 23 endtag => p_endtag); 24 RETURN v_clob; 25 END your_markup; 26 / Function created. SCOTT@orcl_11gR2> SHOW ERRORS No errors. SCOTT@orcl_11gR2> -- query that returns highlighted document: SCOTT@orcl_11gR2> VARIABLE string VARCHAR2(100) SCOTT@orcl_11gR2> EXEC :string := 'test AND demonstration' PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> SELECT your_markup ('document_idx', ROWID, :string) 2 AS highlighted_text 3 FROM document_tab 4 WHERE CONTAINS (document_col, :string) > 0 5 /
HIGHLIGHTED_TEXT
--------------------------------------------------------------------------------
It is a document test of demonstration to highlight.1 selected line.
Scott@orcl_11gR2 >
-
Need help to understand the query result
Hi gurus
I was reading one of the question here in this forum and its link is below:
I had some confusion related to this code and don't understand the logic of the out put, see query below:
Query
with sub_services as
(
Select su_seq 12323, 'HLR1' so_id, 1 seq Union double all the
Select su_seq 12323, "HLR2' so_id, seq 2 Union double all the
Select su_seq 12323, "A09" so_id, seq 3 of all the double union
Select su_seq 12333, "MO1" so_id, seq 4 Union double all the
Select su_seq 12333, "MO2' so_id, seq 5 Union double all the
Select su_seq 12333, "A09" so_id, 6 seq in union double all the
Select su_seq 12333, 'M0CR' so_id, seq 7 Union double all the
Select su_seq 12999, "LOL1' so_id, seq 8 Union double all the
Select su_seq 12999, "LOL2' so_id, seq 9 double
)
Select *.
of sub_services b
where exists (select 1 from sub_services
where su_seq = b.su_seq
and so_id = 'A09.
)
order by 2;
The query result
12323 A09 3
12333 6 A09
12323 HLR1 1
12323 HLR2 2
12333 M0CR 7
12333 4 MO1
12333 5 MO2
According to my understanding, the above query should return records in red only because of her is below command
It exists (select 1 from sub_services
where su_seq = b.su_seq
and so_id = 'A09.
but don't know why he's back 7 files, can someone help me understand the result...
It is query is functionally identical to the PL/SQL block, but much more effective.
declare
number of l_res;
Start
for line (select *)
sub_services) loop
Start
Select 1 from l_res
of sub_services
where su_seq = row.su_seq and
so_id = "A09" and
rownum = 1;
Essentially every row in the outer query are tested against him exists query. Given the correlation between two requests is based only on su_seq each line with a su_seq value returned by him is returned in the output.
Another way to think he uses instead a join condition. This query is equivalent to the query to exist
Select the main
of main sub_services
Join select (separate su_seq
of sub_services
where so_id = "A09") cond
We main.su_seq = cond.su_seq;
John
-
Insert a blank line in the query output
Is it possible to insert a blank line between two rows of the query output?
In the EMP table, the column LINES is as follows:
LINES
1
2
3
4
1
2
3
1
2
3
4
5
I want to insert a blank line after every 1
Please suggest.
SanjayI'm quite puzzled why you need rows in the dataset returned by a select statement that is empty.
If you are using Oracle reports to the release date, you define the presentation of the report to have spaces between the rows returned by the select and have do not need to have the select statement returns a blank line after each line of data. If the output should be obtained by using another client, I think that the customer will have facilities for output formatting.Admit that you really need "blank lines" between data lines, I see only one way: use a temporary table and do an insert into select temporary_table (...) ... from... where... Then, in this temporary table, you can insert 'empty rows', which is actually not really empty, because they must have some fields that give the order of the rows. And then select in temporary_table, you place your order by the columns that are used to give the order for the release.
Thusinsert into temporary_table ( .... ) select ... from ... where ... ; for r in ( select col1, col2, col3 -- columns used for order by from temporary_table order by col1, col2, col3 ) loop insert into temporary_table (col1, col2,col3, col4) values (r.col1,r.col2,r.col3, null); end loop; -- this way, a select * from temporary_tabel order by col1, col2, col3, col4 will return a blank row after each data row
-
Add lines to the query result?
Is it possible to add lines to the result of a shutdown of the SQL query, similar to the CALCULATION command in SQL * more?
In other words, for example, when A column value changes, add a line after the previous line (the last one before changing the column A) to display the sum of the values in column B.
for example
< PRE > A and B
- --
1 3
1 4
1 5
12
2 9
2 1
2-7
1 < / PRE >SQL> create table sales (person,city,sales) 2 as 3 select 'Alice', 'Phoenix', 19 from dual union all 4 select 'Alice', 'Tulsa', 11 from dual union all 5 select 'Bob', 'Phoenix', 17 from dual union all 6 select 'Bob', 'Tulsa', 9 from dual union all 7 select 'Tony', 'Miami', 5 from dual union all 8 select 'Tony', 'San Francisco', 4 from dual union all 9 select 'Tony', 'San Francisco', 3 from dual 10 / Tabel is aangemaakt. SQL> select case grouping_id(person,city,rowid) 2 when 1 then 'Sub-Total for' 3 when 3 then 'Sub-Total for' 4 when 7 then 'Grand Total' 5 end notes 6 , person 7 , city 8 , sum(sales) sales 9 from sales 10 group by rollup(person,city,rowid) 11 having grouping_id(city,rowid) != 1 12 or count(*) > 1 13 order by person 14 , city 15 , grouping(rowid) 16 / NOTES PERSO CITY SALES ------------- ----- ------------- ---------- Alice Phoenix 19 Alice Tulsa 11 Sub-Total for Alice 30 Bob Phoenix 17 Bob Tulsa 9 Sub-Total for Bob 26 Tony Miami 5 Tony San Francisco 4 Tony San Francisco 3 Sub-Total for Tony San Francisco 7 Sub-Total for Tony 12 Grand Total 68 12 rijen zijn geselecteerd.
Kind regards
Rob. -
Please someone help me on the query.
I'm using oracle 11g. The column has many numbers. few are positive numbers, negative numbers are few, and few are zero.
the table structure is as this:
Col1
9
-5
3
60
10
-15
-45
0
87
Now, I have to count the number of positive, negative and all number the number zero of the column and display three columns like this:
Nega_value
Posi_value
Zero_value
3
5
1
What would the query?
Select sum (case when col1< 0="" then="" 1="" end)="">
sum (case when col1 > 0 then 1 end) posi_value,.
sum (case when col1 = 0 then 1 end) zero_value
from your_table
John
-
Need help to write the query to extract the value of the previous row - Lag not help
HelloI created follwing table.
Create table test
(number of fi,
number of fo_fv
number of jup_fv
action varchar2 (10)
);
insert into TEST(1,1,1,'LOAD');
Insert into TEST (2, NULL, 2, "ROLL");
insert into TEST(3,,3,'ROLL');
insert into TEST(4,,4,ROLL);
insert into TEST (5,2,5,LOAD);
I want the result of the query as below:
FI FO_FV JUP_FV ACTION
-------------------------------------------------------------------
1 1 1 LOAD
2 1 2 ROLL
3 1 3 ROLL
4 1 4 ROLL
5 2 5 LOAD
Help, please.
Thank you!
SQL > select fi
2, max (fo_fv) on fo_fv (fi control)
3, jup_fv
4, action
5 of the test;FI FO_FV JUP_FV ACTION
---------- ---------- ---------- ----------
1 1 1 LOAD
ROLL OF 2 1 2
3 1 3 ROLL
4 1 4 ROLL
5 2 5 LOADOR
SQL > select *.
2 test
model 3
Dimension 4 by (fi)
5 measures (fo_fv, jup_fv, action)
6 rules
7 (
8 fo_fv [any] = case when fo_fv [cv ()] is null
9. can fo_fv [cv () - 1]
10 fo_fv [cv () else]
11 end
(12);FI FO_FV JUP_FV ACTION
---------- ---------- ---------- ----------
1 1 1 LOAD
ROLL OF 2 1 2
3 1 3 ROLL
4 1 4 ROLL
5 2 5 LOAD -
Number of lines on the query and export are different?
Hello
I'm kinda new to SQL Developer, but so far it has been very well. I came across a problem, but with a certain query I count the lines and get about 11 000 (which is what I expected), and then export the data to a csv file to download on another system, and somehow the number of lines is increased to 30,000? I tried several times and still get the same results, and I know that the extra lines should not be returned to request bythe they fail when uploaded to the other system.
Does anyone have any idea why this could be? The query is a union query, but it was fine before. Looks like a bug to me, but then again that I am a newbie.
Thank you
SteveThe recordtypeextract r table is not related to any other table. Link with another table and avoid the Cartesian join.
-
Hello
I got the info from a table named X.
Col1 Col2 Col3 Col4
IT01 20 01 X
IT01 20 50 X
IT01 30 01 X
IT01 30 50 X
If the value of "X" all 4 combinations of Col2 and Col3, Col4 the result should be displayed as
Col1, Col4
IT01 X
If the actual values are as
Col1 Col2 Col3 Col4
IT01 20 01 X
IT01 20 50 X
IT01 30 01 X
30 50 IT01 Y
The result should be displayed as
Col1, Col4
IT01 Y
How will generate the query for this?
Thank you
Thomas Titus
Published by: Titus Thomas on April 20, 2010 14:48Try this:
with test_tab as (select 'ITO1' Col1, 20 Col2, 01 Col3, 'X' Col4 from dual union all select 'ITO1' Col1, 20 Col2, 50 Col3, 'X' Col4 from dual union all select 'ITO1' Col1, 30 Col2, 01 Col3, 'X' Col4 from dual union all select 'ITO1' Col1, 30 Col2, 50 Col3, 'X' Col4 from dual union all select 'ITO2' Col1, 20 Col2, 01 Col3, 'X' Col4 from dual union all select 'ITO2' Col1, 20 Col2, 50 Col3, 'X' Col4 from dual union all select 'ITO2' Col1, 30 Col2, 01 Col3, 'X' Col4 from dual union all select 'ITO2' Col1, 30 Col2, 50 Col3, 'Y' Col4 from dual) --- end of mimicking your data; use SQL below: select col1, max(col4) col4 from test_tab group by col1; COL1 COL4 ---- ---- ITO2 Y ITO1 X
-
Hi Experts,
I have a DB table has columns of more than 50.
I question this table, it should only return one line at any time. as sqldeveloper below image.
here, I need to build block pl/sql-query, Discover the column in the table as a key and query result as values.
Eg: Key - Value
TASK_EVENT_ID - 1765
EVENT_TYPE - ASR_UPDATE
... etc until all of the columns in my table.
Experts please comment on that point, appreciate your help on this.
Thank you
-Vincent.
Here is an approach using DBMS_SQL to iterate over the columns of key / value to assign... (Little code snipped for brevity)
create or replace procedure (task_expired)
v_store_id in full,
v_task_action_id in full,
v_job_id in full
)
as
-[SNIP code...]
v_sql VARCHAR2 (4000): = ' select * from my_table where PK = 123'; -Your SQL here!
v_v_val VARCHAR2 (4000);
v_n_val NUMBER;
v_d_val DATE;
v_ret NUMBER;
c NUMBER;
d NUMBER;
col_cnt INTEGER.
f BOOLEAN;
rec_tab DBMS_SQL. DESC_TAB;
col_num NUMBER;
vAsString VARCHAR2 (4000);
BEGIN
-[SNIP code...]
Message_properties. CORRELATION: = "EDF_EVENT";
MSG: = SYS. AQ$ _JMS_BYTES_MESSAGE. Construct();
Msg.set_string_property ('queueName', ' shipping/csi_cth');
Msg.set_string_property ('MODE', 'CR8');
c: = DBMS_SQL. OPEN_CURSOR;
DBMS_SQL. PARSE (c, v_sql, DBMS_SQL. NATIVE);
d: = DBMS_SQL. Execute (c);
DBMS_SQL. DESCRIBE_COLUMNS (c, col_cnt, rec_tab);
1.col_cnt J
LOOP
CASE rec_tab (j) .col_type
WHEN 2 THEN
DBMS_SQL. DEFINE_COLUMN (c, j, v_n_val); -Number
WHEN 12 CAN
DBMS_SQL. DEFINE_COLUMN (c, j, v_d_val); -Date
ON THE OTHER
DBMS_SQL. DEFINE_COLUMN (c, j, v_v_val, 2000); -Else treat as varchar2
END CASE;
END LOOP;
LOOP
v_ret: = DBMS_SQL. FETCH_ROWS (c);
WHEN OUTPUT v_ret = 0;
1.col_cnt J
LOOP
-Fetch each column to the correct data type based on coltype
CASE rec_tab (j) .col_type
WHEN 2 THEN
DBMS_SQL. COLUMN_VALUE (c, j, v_n_val);
vAsString: = to_char (v_n_val);
WHEN 12 CAN
DBMS_SQL. COLUMN_VALUE (c, j, v_d_val);
vAsString: = to_char (v_d_val, ' DD/MM/YYYY HH24:MI:SS');
ON THE OTHER
DBMS_SQL. COLUMN_VALUE (c, j, v_v_val);
vAsString: = v_v_val;
END CASE;
Msg.set_string_property (rec_tab (j) .col_name, vAsString);
END LOOP;
END LOOP;
DBMS_SQL. CLOSE_CURSOR (c);
DBMS_AQ. ENQUEUE (queue_name-online 'cbus.aqjms_common',
Enqueue_options => Enqueue_options,
Message_properties => Message_properties,
Payload-online msg,
Msgid => Message_handle);
dbms_output.put_line ('00 Msgid =' |) Message_handle);
dbms_output.put_line('===Done=');
-[SNIP code...]
END;
/
-
Need help to build the query to group the lines
Hello all, hope someone can help me with this. I am working in Oracle 11 g PL/SQL 11.2.0.2.0.
I have the following query, which does exactly what I need, but I have been invited to consolidate the results in a specific way and I can't do that. First of all the existing request:
I was asked to do, is to display a number of facility_type who have each of the combinations of the 'DEAL' 33 areas. Installation types are strings. So an expected result would look something like:SELECT facility_id ,facility_type ,COUNT (CASE WHEN component_type = 'ATTACH2NDPARTY' THEN 1 END) AS ATTACH2NDPARTY ,COUNT (CASE WHEN component_type = 'ATTACH3RDPARTY' THEN 1 END) AS ATTACH3RDPARTY ,COUNT (CASE WHEN component_type = 'BREAKERGT' THEN 1 END) AS BREAKERGT ,COUNT (CASE WHEN component_type = 'BREAKERUSS' THEN 1 END) AS BREAKERUSS ,COUNT (CASE WHEN component_type = 'CAPACIFORMER' THEN 1 END) AS CAPACIFORMER ,COUNT (CASE WHEN component_type = 'CAPACITOR' THEN 1 END) AS CAPACITOR ,COUNT (CASE WHEN component_type = 'CEFIBEROPTIC' THEN 1 END) AS CEFIBEROPTIC ,COUNT (CASE WHEN component_type = 'ELASTIDISCONN' THEN 1 END) AS ELASTIDISCONN ,COUNT (CASE WHEN component_type = 'NETWORKPROTECT' THEN 1 END) AS NETWORKPROTECT ,COUNT (CASE WHEN component_type = 'POLE' THEN 1 END) AS POLE ,COUNT (CASE WHEN component_type = 'REACTOR' THEN 1 END) AS REACTOR ,COUNT (CASE WHEN component_type = 'RECLOSER3PUPOIL' THEN 1 END) AS RECLOSER3PUPOIL ,COUNT (CASE WHEN component_type = 'RECLOSERTSUP' THEN 1 END) AS RECLOSERTSUP ,COUNT (CASE WHEN component_type = 'RECLSR3PCNTRL3A' THEN 1 END) AS RECLSR3PCNTRL3A ,COUNT (CASE WHEN component_type = 'RECLSR3PCNTRLNT' THEN 1 END) AS RECLSR3PCNTRLNT ,COUNT (CASE WHEN component_type = 'RECLSRTSCNTRL' THEN 1 END) AS RECLSRTSCNTRL ,COUNT (CASE WHEN component_type = 'RECTIFIERUSS' THEN 1 END) AS RECTIFIERUSS ,COUNT (CASE WHEN component_type = 'REGULATORJOINT' THEN 1 END) AS REGULATORJOINT ,COUNT (CASE WHEN component_type = 'REGULATOROH' THEN 1 END) AS REGULATOROH ,COUNT (CASE WHEN component_type = 'REGULATORUSS' THEN 1 END) AS REGULATORUSS ,COUNT (CASE WHEN component_type = 'RMS' THEN 1 END) AS RMS ,COUNT (CASE WHEN component_type = 'SPLICEPRIMARY' THEN 1 END) AS SPLICEPRIMARY ,COUNT (CASE WHEN component_type = 'STREETLIGHT' THEN 1 END) AS STREETLIGHT ,COUNT (CASE WHEN component_type = 'SWITCHSCADA' THEN 1 END) AS SWITCHSCADA ,COUNT (CASE WHEN component_type = 'TAPCHANGER' THEN 1 END) AS TAPCHANGER ,COUNT (CASE WHEN component_type = 'TRAFFICSIGNAL' THEN 1 END) AS TRAFFICSIGNAL ,COUNT (CASE WHEN component_type = 'TRANSF480' THEN 1 END) AS TRANSF480 ,COUNT (CASE WHEN component_type = 'TRANSFGROUND' THEN 1 END) AS TRANSFGROUND ,COUNT (CASE WHEN component_type = 'TRANSFISOLATION' THEN 1 END) AS TRANSFISOLATION ,COUNT (CASE WHEN component_type = 'TRANSFOH' THEN 1 END) AS TRANSFOH ,COUNT (CASE WHEN component_type = 'TRANSFUG' THEN 1 END) AS TRANSFUG ,COUNT (CASE WHEN component_type = 'TRANSFURD' THEN 1 END) AS TRANSFURD ,COUNT (CASE WHEN component_type = 'TRANSFUSS' THEN 1 END) AS TRANSFUSS FROM (SELECT fy.id AS facility_id ,fy.external_facility_id ,fy.flty_facility_type as facility_type ,cp.cpty_component_type as component_type FROM facilities fy LEFT OUTER JOIN components cp ON cp.facility_id= fy.id ORDER BY fy.id DESC) GROUP BY facility_id, facility_type
FACILITY_TYPE | ATTACH2NDPARTY | ATTACH3RDPARTY | BREAKERGT | ... TRANSFUSS | COUNTY
MANHOLE X X 10
MANHOLE X X 22
POLE X X 5
and so on. Because there are 33 BUSINESS areas and therefore 33! possible combinations, I was thinking about a sort of loop would achieve the desired result, but I'm stuck and could really use a shot in the arm. Any help will be appreciated and obtained points! Thanks in advance.select facility_type ,ATTACH2NDPARTY ,ATTACH3NDPARTY -- and so on , count(*) cnt from ( --your query SELECT facility_id ,facility_type ,COUNT (CASE WHEN component_type = 'ATTACH2NDPARTY' THEN 1 END) AS ATTACH2NDPARTY ,COUNT (CASE WHEN component_type = 'ATTACH3RDPARTY' THEN 1 END) AS ATTACH3RDPARTY ,COUNT (CASE WHEN component_type = 'BREAKERGT' THEN 1 END) AS BREAKERGT ... ) group by facility_type ,ATTACH2NDPARTY ,ATTACH3NDPARTY -- and so on like in projection
-
Need help to resolve the query by using analytic functions
Hello
I need help to solve this problem, I tried an analytical function but could not solve the problem.
I have three table as illustrated below the table is filled with a flat file. The records are arranged sequentailly based on the name of the file.
The first record of the game based on EIN goes to TAB_RCE
the following records then goes to TAB_RCW
and last save of the game based on EIN goes to the RCT table
How can I make groups and
assign a
EIN * 12345 * line number * 02, 03, 04 * in the table TAB_RCW and * 05 * in the table TAB_RCT
EIN * 67890 * line number * 07, 08, 09,10 * in the table TAB_RCW and * 11 * in the table TAB_RCT
and so on...
Thank you
Rajesh
TAB RCE_--------------------------------------------------------------
LineNumber EIN FILENAME TYPE
-----
01 12345 ABC NCE. TXT
06 67890 ABC NCE. TXT
12 76777 ABC NCE. TXT
-----
TAB_RCW
-----
LineNumber TYPE SSN FILENAME
-----
02 22222 ABC RCW. TXT
03 33333 ABC RCW. TXT
04 44444 ABC RCW. TXT
07 55555 ABC RCW. TXT
08 66666 ABC RCW. TXT
09 77777 ABC RCW. TXT
10 88888 ABC RCW. TXT
13 99998 ABC RCW. TXT
14 99999 ABC RCW. TXT
-----
TAB_RCT
-----
NAME OF THE FILE OF TYPE LINENUMBER
-----
RCT 05 ABC. TXT
RCT 11 ABC. TXT
RCT 15 ABC. TXT
-----SQL> with TAB_RCE as ( 2 select 'RCE' rtype,'01' linenumber, '12345' EIN,'ABC.TXT' FILENAME from dual union all 3 select 'RCE','06','67890','ABC.TXT' from dual union all 4 select 'RCE','12','76777','ABC.TXT' from dual 5 ), 6 TAB_RCW as ( 7 select 'RCW' rtype,'02' linenumber,'22222' ssn,'ABC.TXT' FILENAME from dual union all 8 select 'RCW','03','33333','ABC.TXT' from dual union all 9 select 'RCW','04','44444','ABC.TXT' from dual union all 10 select 'RCW','07','55555','ABC.TXT' from dual union all 11 select 'RCW','08','66666','ABC.TXT' from dual union all 12 select 'RCW','09','77777','ABC.TXT' from dual union all 13 select 'RCW','10','88888','ABC.TXT' from dual union all 14 select 'RCW','13','99998','ABC.TXT' from dual union all 15 select 'RCW','14','99999','ABC.TXT' from dual 16 ), 17 TAB_RCT as ( 18 select 'RCT' rtype,'05' linenumber,'ABC.TXT' FILENAME from dual union all 19 select 'RCT','11','ABC.TXT' from dual union all 20 select 'RCT','15','ABC.TXT' from dual 21 ) 22 select rtype, 23 last_value(ein ignore nulls) over(partition by filename order by linenumber) ein, 24 linenumber, 25 ssn 26 from ( 27 select rtype, 28 linenumber, 29 ein, 30 to_char(null) ssn, 31 filename 32 from TAB_RCE 33 union all 34 select rtype, 35 linenumber, 36 to_char(null) ein, 37 ssn, 38 filename 39 from TAB_RCW 40 union all 41 select rtype, 42 linenumber, 43 to_char(null) ein, 44 to_char(null) ssn, 45 filename 46 from TAB_RCt 47 ) 48 order by linenumber 49 / RTY EIN LI SSN --- ----- -- ----- RCE 12345 01 RCW 12345 02 22222 RCW 12345 03 33333 RCW 12345 04 44444 RCT 12345 05 RCE 67890 06 RCW 67890 07 55555 RCW 67890 08 66666 RCW 67890 09 77777 RCW 67890 10 88888 RCT 67890 11 RTY EIN LI SSN --- ----- -- ----- RCE 76777 12 RCW 76777 13 99998 RCW 76777 14 99999 RCT 76777 15 15 rows selected. SQL>
SY.
-
help me create a column with the time format
Hi all
Please help me find the query to create a table with 3 columns and insert the following data
ENTITYID | CHGDATE | CHGTIME
======= ==================== ========
4214984 | 2 OCTOBER 06 12.00.00.000000 AM | 07:23:57
4214985 | 12.00.00.000000 11-SEP-08 AM | 10:52:19
and update of the first line of the above table as follows
---------------------
4214984 | 2 OCTOBER 06 07.23.57.000000 AM | 07:23:57
------------------------
you will need to update the CHGDATE column with the time of the CHGTIME column.Sorry, we need a new format around the to_date
select to_date(to_char(chgdate, 'mm/dd/yyyy') || ' ' || to_char(chgtime, 'hh24:mi:ss'), 'mm/dd/yyyy hh24:mi:ss') from etime3;
This should telll Oracle to the format of the generated string. If this isn't the case, run select with the to_char two as separate columns to see that get us the data that we expect.
-
Hi, can someone help me with the query. I try to display comm based on calculation below
SAL < 5000 then 10%
5000 - 10000 then 15%
> 10000 then 20%
This is the query
DECLARE
v_comm number (7.2);
v_Name emp.ename%type;
v_empno emp.empno%type;
v_sal emp.sal%type;
BEGIN
SELECT ename, empno, sal IN
v_Name, v_empno, v_sal
EMP;
v_comm: = (IF v_sal < v_sal*.10 then 5000;)
ELSIF v_sal between 5001 AND 10000 THEN v_sal*.15;
Of ANOTHER v_sal > 10001 THEN v_sal*.20;
END IF ;);
dbms_output.put_line(v_Name||) e with empno' | v_empno | "win a comm' | v_comm);
END; /
also tried
DECLARE
v_comm number (7.2);
v_Name emp.ename%type;
v_empno emp.empno%type;
v_sal emp.sal%type;
BEGIN
SELECT ename, empno, sal IN
v_Name, v_empno, v_sal
EMP;
IF v_sal < v_comm then 5000: = v_sal*.10;
ELSIF v_sal between 5001 AND 10000 THEN v_comm: = v_sal*.15;
Of ANOTHER v_sal > 10001 THEN v_comm: = v_sal*.20;
END IF ;);
dbms_output.put_line(v_Name||) e with empno' | v_empno | "win a comm' | v_comm);
END;
/
Hello
Look at the syntax of the IF in the PL/SQL manual. Comapre to the instruction BOX and also the expression BOX.
Perhaps, instead of an IF statement
v_comm: = (IF v_sal<5000 then="">5000>
ELSIF v_sal between 5001 AND 10000 THEN v_sal*.15;
ELSE v_sal > 10001 THEN v_sal*.20;
END IF ;);
you wanted to write an expression BOX, like this:
v_comm: = BOX
WHEN v_sal< 5000 ="" then="" v_sal="" *="">
WHEN v_sal BETWEEN 5001 AND 10000 THEN v_sal *.15
WHEN v_sal > 10001 THEN v_sal *.20
END;
Or perhaps cela:
v_comm: = v_sal * CASE
WHEN v_sal<= 5000="" then="">= >
WHEN v_sal<= 10000="" then="">=>
OF AUTRE.20
END;
You can also use a CASE expression in the SELECT statement.
Maybe you are looking for
-
Evry time I open a new tab, I want google search to be here, hoe do
When I start a new tab, I would like the page to search google, currently all new tabs are blank pages...
-
I am running the latest version of El Capitan, and I tried to restart the computer and the applications of countless times. I have nowhere to go in this situation! I tried to use different WiFi. I tried to delete the plist of network document and I f
-
Satellite L - F3-F200-0002 error in the Recovery Wizard
Just brought the computer to the store and he came out of the box to set up and came with Toshiba Recovery Wizard then error: F3-F200-0002, it says to click OK to close. How to cancel it to start my computer's configuration?
-
Can I switch from Vista Ultimate 32 bit for Windows 7 Pro 64 bit
I have a Vista Ultimate 32 bit legtitimate, I've never used and I want to upgrade to a legitimate Windows 7 Professional 64 bit. Is it possible to do it and how?
-
Tengo PLOTS one y no PUEDO bajarlas. El error da're el 80246008. El Comando "incio del Fondo Inteligente (bits) transfer service" me ha notice. No if Se Ahí Todo el Problema eStara. What puedo HACER?. Saludos.