Help turn the query that returns single return system
Hello, I have two tables, readings, and values. Values have a foreign key to the readings.create table readings
(
id number primary key,
point number,
datereading date
);
create table reading_values
(
id number primary key,
counter_nr number,
point number,
reading_id number,
datereading date,
CONSTRAINT fk_reading
FOREIGN KEY (reading_id)
REFERENCES readings (id)
);
The point and datereadings columns have the same value of related rows.insert into readings values (1, 1234, to_date('20100622 12:12', 'yyyymmdd HH24:MI'));
insert into reading_values values (1, 0, 1234, 1, to_date('20100622 12:12', 'yyyymmdd HH24:MI')); --row1
insert into reading_values values (2, 1, 1234, 1, to_date('20100622 12:12', 'yyyymmdd HH24:MI')); --row2
insert into readings values (2, 1234, to_date('20100623 12:12', 'yyyymmdd HH24:MI'));
insert into reading_values values (3, 0, 1234, 2, to_date('20100623 12:12', 'yyyymmdd HH24:MI')); --row3
insert into reading_values values (4, 1, 1234, 2, to_date('20100623 12:12', 'yyyymmdd HH24:MI')); --row4
insert into readings values (3, 1111, to_date('20100621 12:12', 'yyyymmdd HH24:MI'));
insert into reading_values values (5, 0, 1111, 3, to_date('20100623 12:12', 'yyyymmdd HH24:MI')); --row5
Now I have the procedure which the entry: p_point and p_date.select * from reading_values rv,
(select * from (select id, datereading
from readings where datereading < p_date and point = p_point
order by datereading desc) where rownum <= 1) t where rv.reading_id = t.id
so I want the previous reading_values (in time based on p_date) for a certain point p_date. I hope this makes sense?Example:
select * from reading_values rv,
(select * from (select id, datereading
from readings where datereading < to_date('20100624 12:12', 'yyyymmdd HH24:MI') and point = 1234
order by datereading desc) where rownum <= 1) t where rv.reading_id = t.id
returns row 3 and 4
Now, what I want to do, is replace p_point and p_date with two collections. For example: p_points = [1234, 1111] p_dates = [20100622 15:12, 20100624 12:12]Here, I want to have the previous reading_values by point = 1234 and datereading < 20100622 order 15:12 by datereading (where rownum < = 1).
and also reading_values by point = 1111 and datereading < 20100624 order 12:12 by datereading (where rownum < = 1).
This should return line1, line2 and row5...
So far I came up with this. But I can't be sure that it is correct. And the performance seems to be horrible (cost 88, 13 recursive calls, 155 becomes uniform) for a query with 2 entry points and 2 dates compared to the original to just a single point query and the date of entry (cost 13, 1 recursive call and gets 14 coherent).
Select rv.* from (SELECT r.id
FROM Readings r,
(select rownum rn1, t1.id from table1 t1 order by id) t1, -- input parameter1 (point collection)
(select rownum rn2, t2.date_now from table1 t2 order by id) t2 -- input parameter 2 (date collection)
WHERE r.point = t1.id
AND r.datereading = (SELECT max(r2.datereading)
FROM Readings r2
WHERE r2.point = t1.id
AND r2.datereading < t2.date_now AND rn1 = rn2)
) r, Reading_Values rv where r.id= rv.reading_id;
code for creating table 1 that I used instead of collections of entry:create table table1
(
id number not null primary key,
date_now date not null
);
insert into table1 values (1234, to_date('20100622 15:12', 'yyyymmdd HH24:MI'));
insert into table1 values (1111, to_date('20100624 12:12', 'yyyymmdd HH24:MI'));
Hope someone can help me on my way :) Please ask if something is unclear or strange! Thank you!Published by: KarlTrumstedt on 23-jun-2010 06:20
Try this
SELECT RV.ID, RV.COUNTER_NR, RV.POINT, RV.READING_ID, RV.DATEREADING
FROM (
SELECT ( SELECT LAST_VALUE(RE.ID) OVER
(PARTITION BY RE.POINT ORDER BY RE.DATEREADING)
FROM READINGS RE
WHERE RE.DATEREADING < T1.DATE_NOW AND RE.POINT = T1.ID
) ID,
T1.ID POINT,
T1.DATE_NOW
FROM TABLE1 T1
) X
JOIN READING_VALUES RV
ON (X.ID = RV.READING_ID AND X.POINT = RV.POINT)
;
Tags: Database
Similar Questions
-
Help with the query to return the last possible value
Can someone please help me to create a query for the situation below?
Table: TABLEA
Columns:
FACID VARCHAR2 (10),
DEPTID VARCHAR2 (10),
CHARGENUMBER NUMBER (10)
I have the following data:
A, B, 1
A, B, 2
C, D, 3
C, D, 4
I will return the following:
A, B, 2
C, D, 4
In other words, I would return the last possible CHARGENUMBER for FACID and DEPTID.
The table has no index, and it is responsible for a worksheet in that order.
Thank you very much!Hello
If you have a TIMESTAMP column, called entry_dt, you can use a Top - N query like this to find the last x entries.
WITH got_rnum AS ( SELECT my_table.* , RANK () OVER (ORDER BY entry_dt DESC) AS rnum FROM my_table ) SELECT * -- or list all columns except rnum FROM got_rnum WHERE rnum <= x ;
It is very common to have a trigger to ensure that columns like entry_dt are met.
If you have only one statement that inserts with hundreds of lines, they can all have the same entry_dt. (The value of SYSTIMESTAMP is constant throughout a statement, even if it takes a few seconds).
The above query uses RANK, so if you tell him you want the last 10 entries, it can return more than 10, because it includes all lines with exactly the same entry_dt as the 10th. If you want to exactly 10 rows returned, even if there is a tie for 10th place, then use ROW_NUMBER instead of RANK; the rest of the query is the same. -
Help with the query to return the results of the group in the table?
Hello
Im a total noob, so please be nice...!
I'm looking around a table contains a column of WORD and a WORD_TYPE_ID column.
Words can have the same type_id.
What I'm trying to do is to write a query that will return the longest word for each word_type_id.
I tried for hours to get it and everything seems to get is two error messages or just the longest word in the whole WORD column.
Is the furthest I can get before things break down...
Select Word
table
where
Length (Word) =
(
Select
Max (length (Word))
table
)
Any help on this or if I could be pointed in the right direction it would be greatly appreciated.
Thank youHello
Welcome to the forum!
Here's one way:
SELECT word_type_id , MIN (word) KEEP (DENSE_RANK LAST ORDDER BY LENGTH (word)) AS longest_word FROM table_x GROUP BY word_type_id;
If there be a tie in some word_type_id (i.e. 2 or more words have exactly the same length, which is the longest in this group) the expression above will return the first one alphabetically. (This is what means here MIN.)
Published by: Frank Kulash, 11 August 2009 13:56
You almost had it.
As you have noticed, you get the longest line across the table. This is because your subquery was watching the entire table.
If you to correlate the subquery to the row in the main table, as shown below, you can get the longest word in each group:select word from table m -- m for main where length (word) = ( select max (length(word)) from table where word_type_id = m.word_type_id -- New );
-
Need help to write a MySQL query that returns only the peer matching records
Because I don't know how to explain it easily, I use the table below as an example.
I want to create a MySQL query that returns only the records that match counterparts where 'col1' = 'ABC '.
Notice the ' ABC / GHI' record does not have a Counter-match ' GHI / ABC' record. This record must not be returned because there is no Counter-Party correspondent. With this table, the ' ABC / GHI' record should be the one returned in the query.
How can I create a query that will do it?
ID | col1 | col2
--------------------
1. ABC | DEF
2. DEF | ABC
3. ABC | IGS
4. DEF | IGS
5. IGS | DEF
* Please let me know if you have no idea of what I'm trying to explain.I wanted to just the results where col1 = ABC, but I already got the answer I needed on another forum. Thank you anyway.
SELECT a.col1,
a.col2
FROM table_name AS a
LEFT OUTER
Table_name JOIN b
ON b.col1 = a.col2
AND a.col1 = b.col2
WHERE b.col1 IS NOT NULL AND a.col1 = 'ABC '. -
I need a query that returns the average amount of characters from text colum in MS SQL.
I need a query that returns the average amount of characters from text colum in MS SQL.
Could someone show me how?Sorting, I need of the
DATALENGTH
function
-
Query that returns number 1 - Add additional columns based on percentages
I have a query that returns a large number. The return value will always be a single field (a column, a line, a single value).
I need to have also three other columns in the return of this request: one that returns a number that is 50% of the original number, one that returns a number that is 75% of the original number, and one that is double the original number. How is that possible? If anyone can point me to examples, it would be a great help. I got the results mixed by searching, so I'm not sure good practices.
Thank you for the input in advance.
Hello
Whenever you have a question, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the accurate results you want from this data, so that people who want to help you can recreate the problem and test their ideas.
Explain, using specific examples, how you get these results from these data.
If you show what you want to do using commonly available tables, like those of the scott schema, then you don't need to display the sample data; just results and explanations.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: Re: 2. How can I ask a question on the forums?
I'm not sure that understand the question.
If x is a number, then
.50 * x is 50% of this number,
.75 * x is 75% of that number, and
2 * x is to double this figure.
You can get them all in the same query, if you want to. For example:
SELECT ename
sal
.50 * sal AS p_50
.75 * sal AS p_75
2 * sal AS dbl
FROM scott.emp;
Output:
ENAME SAL P_50 P_75 DBL
---------- ---------- ---------- ---------- ----------
SMITH, 800, 400, 600, 1600
1600 800 1200 3200 ALLEN
1250 625 WARD 937,5 2500
JONES 2975 1487.5 2231,25 5950
1250 625 MARTIN 937,5 2500
2850 1425 BLAKE 2137,5 5700
2450 1225 CLARK 1837,5 4900
3000 1500 2250 6000 SCOTT
KING 5000 2500 3750 10000
1500 750 1125 3000 TURNER
1100 550 825 2200 ADAMS
JAMES 950 475 712,5 1900
FORD 3000 1500 2250 6000
1300 650 975 2600 MILLER
Is that what you ask?
-
Is there a way to combine their results of the query in a single function
I have a bunch of functions that return a query:
< cffunction = access "getDeals" name = "remote" returntype = "query" >
< cffunction = access "getDeals2" name = "remote" returntype = "query" >
is there a way to combine their results of the query in a single function that returns a structure of different results?
Uh, it is probably more suited to a table - effectively turning it into a list of queries. Then you loop the array and each output.
I use a similar approach in the creation of the system of the user messages. Most of my functions that are called do their part, then at the end call another function, I called 'messages '. This function takes all what my function sends and adds it to a message board.
Keeps me out of a long list of messages - because I could call several functions at the same time. If I have just the output of a message of each function, each would crush the other. So, I'd get one message at a time.
Immediately after that he was released, I will destroy it then the message table so that messages are not kept inside.
Mikey.
-
We can find the size of the query that is extracted in the selection operation?
Hello
We organize a query select and found that the query is retriving records (rows) 953368. Now is it possible to calculate what this query in terms of size. ??
Could you pls suggest me.
Thank you
Srini...>
We organize a query select and found that the query is retriving records (rows) 953368
>
Yes, but how many different tables are involved? The number of columns? What are the data types of the columns?
If I run a query that returns a single line, it could have 900 columns defined as CHAR (4000), or a column defined as char (1).Length of line is therefore somewhere between rows 1 million times 1 byte and 3.6 MB.
I'm guessing 1 million bytes minimum and 3.6 GB on the high side.
-
Need help with the query string manipulation
Hello
With the help of 10.1.0.4.2
Given a table called PREFIX_CODES that contains a column called PREFIX_CODE
with the following data:
PREFIX_CODE - VARCHAR2 (20)
-------------------
AAA
BENAMER
CARTER
and another table called SUBSCRIBERS with a column called SUBSCRIBER_ID
with the following data:
SUBSCRIBER_ID - VARCHAR2 (30)
---------------------
BBBB-123456
AAA-444444
DD-2222222
EEEE-888888
Is there a query that will pull all the SUBSCRIBER_ID that begin with
each of the PREFIX_CODES? The following query is not valid, but it
This will give you an idea of what I'm trying to do:
SELECT SUBSCRIBER_ID
SUBSCRIBERS
WHERE AS SUBSCRIBER_ID (SELECT PREFIX_CODE |) » %'
OF PREFIX_CODES)
Using the data from above, I would like that the query to return:
BBBB-123456
AAA-444444
Thanks for your help!Hello
Welcome to the forum!
You were on the right track. To find if a given subscriber corresponds to any prefix_code, you can do an EXISTS subquery:
SELECT subscriber_id FROM subsribers s WHERE EXISTS ( SELECT NULL FROM prefix_codes WHERE s.subscriber_id LIKE prefix_code || '%' ) ;
This will tell you if at least a prefix code. It won't tell you exactly how many, or what they were.
Your message, I'm guessing that there may be more than one, and you can deduct the subscriber_id itself, then the above query should work for you. -
Turn the query into a GROUP BY
I'm turning the query below, so he produced the first line of each user, each combination of responsibility:
Select a.LOGIN_ID, a.START_TIME, a.END_TIME, c.RESPONSIBILITY_NAME, b.USER_ID, d.USER_NAME in the FND_LOGIN_RESPONSIBILITIES,
For a unique combination of the user and the responsibility, it should only return the first value. Currently it is multiple outputs back int the format:fnd_logins b, FND_RESPONSIBILITY_tl c, fnd_user d where a.LOGIN_ID=b.LOGIN_ID and a.RESPONSIBILITY_ID=c.RESPONSIBILITY_ID and b.USER_ID=d.USER_ID order by d.user_name, c.responsibility_name, a.end_TIME desc nulls last
This should only output as below:LOGIN_ID START_TIM END_TIME RESPONSIBILITY_NAME USER_ID USER_NAME ---------- --------- --------- ------------------------------------------------------- ---------- ------------------------------------------------------- 1487207 23-NOV-11 23-NOV-11 XXX Payables Supervisor 1236 ZZZ 1487207 23-NOV-11 23-NOV-11 XXX Payables Supervisor 1236 ZZZ 1480785 22-NOV-11 22-NOV-11 XXX Payables Supervisor 1236 ZZZ 1478246 22-NOV-11 22-NOV-11 XXX Payables Supervisor 1236 ZZZ 1478246 22-NOV-11 22-NOV-11 XXX Payables Supervisor 1236 ZZZ 3149187 14-DEC-12 14-DEC-12 XXX Imprest Employee Responsibility 5825 3136830 11-DEC-12 11-DEC-12 XXX Imprest Employee Responsibility 5825 ZZZ 3102226 03-DEC-12 03-DEC-12 XXX Imprest Employee Responsibility 5825 ZZZ 3094387 30-NOV-12 30-NOV-12 XXX Imprest Employee Responsibility 5825 ZZZ 3094387 30-NOV-12 30-NOV-12 XXX Imprest Employee Responsibility 5825 ZZZ 3093463 29-NOV-12 29-NOV-12 XXX Imprest Employee Responsibility 5825 ZZZ 3090327 29-NOV-12 29-NOV-12 XXX Imprest Employee Responsibility 5825 ZZZ
My version of the database is 11.2.0.2.0LOGIN_ID START_TIM END_TIME RESPONSIBILITY_NAME USER_ID USER_NAME ---------- --------- --------- ------------------------------------------------------- ---------- ------------------------------------------------------- 1487207 23-NOV-11 23-NOV-11 XXX Payables Supervisor 1236 ZZZ 3149187 14-DEC-12 14-DEC-12 XXX Imprest Employee Responsibility 5825 ZZZ
JamesA way
select * from ( select a.LOGIN_ID,a.START_TIME,a.END_TIME, c.RESPONSIBILITY_NAME,b.USER_ID,d.USER_NAME, row_number() over(partition by d.user_name, c.responsibility_name order by a.end_TIME desc nulls last ) rn from FND_LOGIN_RESPONSIBILITIES a, fnd_logins b, FND_RESPONSIBILITY_tl c, fnd_user d where a.LOGIN_ID=b.LOGIN_ID and a.RESPONSIBILITY_ID=c.RESPONSIBILITY_ID and b.USER_ID=d.USER_ID ) where rn = 1 order by user_name, responsibility_name
-
Need help with the query. Help, please
Hey everyone, need your help. Thank you in advance. In my view, there is function Pivot. Just do not know how to use this function. I have the query that works. The result is:
11-111-1111 Vlad 16505 01/04/2013 5 August 13 dental plan pre-tax amount 29,65
11-111-1111 Vlad 16505 01/04/2013 dental pre-tax 5 August 13 Plan level EE + SP
11-111-1111 16505 Vlad 01/04/2013 5 August 13 pre-tax Option TOP dental plan
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax dental care plan pay the value
11-111-1111 16505 Vlad 01/04/2013 dental pre-tax 5 August 13 Plan period Type
11-111-1111 Vlad 16505 01/04/2013 amount pre-tax medical Plan of 5 August 13 149
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax Medical Plan level EE + SP
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax Plan medical Option MED
11-111-1111 Vlad 16505 01/04/2013 5 August 13 plan pre-tax pay value
11-111-1111 16505 Vlad 01/04/2013 5 August 13 pre-tax Medical Plan period Type
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax Plan PPO medical Plan
11-111-1111 Vlad 16505 01/04/2013 5 August 13 Vision Plan amount 5.94 pre-tax
But I need the result to be
Amount of SSN ID name item level Option PayValue period Type
11-111-1111 Vlad 16505 01/04/2013 null null high of 5 August 13 pre-tax Dental Plan 29,65 EE + SP
11-111-1111 Vlad 16505 01/04/2013 null null MED 5 August 13 149 medical plan pre-tax EE + SP
11-111-1111 Vlad 16505 01/04/2013 Vision Plan before taxes of 5 August 13
Select distinct
' 11-111-1111 "as ssn,
WOMEN'S WEAR. Employee_number,
"Vlad" as EMPLOYEE_FULL_NAME,
TO_CHAR (papf.start_date, "MM/DD/YYYY") as Date_Of_Hire
a.effective_start_date,
PETF.element_name,
pivf. Name,
peevf.screen_entry_valueOf
PER_all_PEOPLE_F women's wear
per_assignments_f A
pay_element_types_f petf
pay_element_links_f pelf
PAY_ELEMENT_ENTRIES_F penf
PAY_ELEMENT_ENTRY_VALUES_F peevf
pay_input_values_f pivf
WHERE
PETF.element_name ('Dental Plan before taxes', 'Medical Plan before taxes', "Vision Plan before taxes")
and petf. ELEMENT_TYPE_ID = pelf. ELEMENT_TYPE_ID
and (trunc (sysdate) BETWEEN pelf. EFFECTIVE_START_DATE AND pelf. EFFECTIVE_END_DATE)
and (pelf. ELEMENT_LINK_ID = penf. ELEMENT_LINK_ID and a.assignment_id = penf. ASSIGNMENT_ID)
and (trunc (sysdate) BETWEEN penf. EFFECTIVE_START_DATE AND penf. EFFECTIVE_END_DATE)
and penf. ELEMENT_ENTRY_ID = peevf. ELEMENT_ENTRY_ID
and peevf. INPUT_VALUE_ID = pivf. INPUT_VALUE_ID
AND papf.employee_number IS NOT NULL
AND A.assignment_type = 'E '.
AND A.person_id = papf.person_id
and papf.effective_end_date > sysdate
and a.effective_end_date > sysdate
and (trunc (sysdate) BETWEEN women's wear. EFFECTIVE_START_DATE AND women's wear. EFFECTIVE_END_DATE)
and a.effective_start_date = (select MAX (effective_start_date) from PER_ASSIGNMENTS_f where assignment_id = a.assignment_id)
and a.assignment_id = 42643
and a.assignment_status_type_id = '1'
order of petf.element_name;Change with your query
SELECT * FROM (select distinct)
' 11-111-1111 "as ssn,
WOMEN'S WEAR. Employee_number,
"Vlad" as employee_full_name,
TO_CHAR (papf.start_date, "MM/DD/YYYY") as date_of_hire
a.effective_start_date,
PETF.element_name,
pivf. Name,
peevf.screen_entry_value
Of
PER_all_PEOPLE_F women's wear
per_assignments_f A
pay_element_types_f petf
pay_element_links_f pelf
PAY_ELEMENT_ENTRIES_F penf
PAY_ELEMENT_ENTRY_VALUES_F peevf
pay_input_values_f pivf
WHERE
PETF.element_name ('Dental Plan before taxes', 'Medical Plan before taxes', "Vision Plan before taxes")
and petf. ELEMENT_TYPE_ID = pelf. ELEMENT_TYPE_ID
and (trunc (sysdate) BETWEEN pelf. EFFECTIVE_START_DATE AND pelf. EFFECTIVE_END_DATE)
and (pelf. ELEMENT_LINK_ID = penf. ELEMENT_LINK_ID and a.assignment_id = penf. ASSIGNMENT_ID)
and (trunc (sysdate) BETWEEN penf. EFFECTIVE_START_DATE AND penf. EFFECTIVE_END_DATE)
and penf. ELEMENT_ENTRY_ID = peevf. ELEMENT_ENTRY_ID
and peevf. INPUT_VALUE_ID = pivf. INPUT_VALUE_ID
AND papf.employee_number IS NOT NULL
AND A.assignment_type = 'E '.
AND A.person_id = papf.person_id
and papf.effective_end_date > sysdate
and a.effective_end_date > sysdate
and (trunc (sysdate) BETWEEN women's wear. EFFECTIVE_START_DATE AND women's wear. EFFECTIVE_END_DATE)
and a.effective_start_date = (select MAX (effective_start_date) from PER_ASSIGNMENTS_f where assignment_id = a.assignment_id)
and a.assignment_id = 42643
and a.assignment_status_type_id = '1')
PIVOT (MAX (screen_entry_value) FOR (name) TO ("Amount" AS 'Amount', 'level' AS 'level', 'Option High' AS 'High Option', 'Pay the value' AS 'Value to pay', 'Period of Type' AS 'Type period'))
order by element_name;
(GOLD)
SELECT ssn,
Employee_number,
employee_full_name,
date_of_hire,
effective_start_date,
element_name,
Max (decode (Name, 'Amount', screen_entry_value)) 'amount. "
Max (decode (Name, 'Level', screen_entry_value)) 'level ',.
MAX (DECODE (name, "High Option", screen_entry_value)) "High Option",
MAX (DECODE (name, 'Value of pay', screen_entry_value)) 'value of pay. "
MAX (DECODE (name, 'Period Type', screen_entry_value)) 'period of Type '.
FROM (select distinct)
' 11-111-1111 "as ssn,
WOMEN'S WEAR. Employee_number,
"Vlad" as employee_full_name,
TO_CHAR (papf.start_date, "MM/DD/YYYY") as date_of_hire
a.effective_start_date,
PETF.element_name,
pivf. Name,
peevf.screen_entry_value
Of
PER_all_PEOPLE_F women's wear
per_assignments_f A
pay_element_types_f petf
pay_element_links_f pelf
PAY_ELEMENT_ENTRIES_F penf
PAY_ELEMENT_ENTRY_VALUES_F peevf
pay_input_values_f pivf
WHERE
PETF.element_name ('Dental Plan before taxes', 'Medical Plan before taxes', "Vision Plan before taxes")
and petf. ELEMENT_TYPE_ID = pelf. ELEMENT_TYPE_ID
and (trunc (sysdate) BETWEEN pelf. EFFECTIVE_START_DATE AND pelf. EFFECTIVE_END_DATE)
and (pelf. ELEMENT_LINK_ID = penf. ELEMENT_LINK_ID and a.assignment_id = penf. ASSIGNMENT_ID)
and (trunc (sysdate) BETWEEN penf. EFFECTIVE_START_DATE AND penf. EFFECTIVE_END_DATE)
and penf. ELEMENT_ENTRY_ID = peevf. ELEMENT_ENTRY_ID
and peevf. INPUT_VALUE_ID = pivf. INPUT_VALUE_ID
AND papf.employee_number IS NOT NULL
AND A.assignment_type = 'E '.
AND A.person_id = papf.person_id
and papf.effective_end_date > sysdate
and a.effective_end_date > sysdate
and (trunc (sysdate) BETWEEN women's wear. EFFECTIVE_START_DATE AND women's wear. EFFECTIVE_END_DATE)
and a.effective_start_date = (select MAX (effective_start_date) from PER_ASSIGNMENTS_f where assignment_id = a.assignment_id)
and a.assignment_id = 42643
and a.assignment_status_type_id = '1')
GROUP BY ssn, employee_number, employee_full_name, date_of_hire, effective_start_date, NOM_ELEMENT
order by element_name;
-
Help with the query to select only one record from the result set in double
Hello
Please help with the query. Version of Oracle database we use is 10g R2.
I have a vision that is duplicated IDS, but they are used across the different functions. See below examples of data. Please help me with a query to select only one record (based on ID regardless of the area) from the bottom of the result set of duplicate records. For what is the point of view is there unique records, given the combination of the fields ID, Org, DF, dry, Sub-Sec
ID Org DF Sec Sub-Sec (163) CQ CPDM CPDM HD (163) PC ENG ENG ENG (163) CQ ASIC ASIC IS 8888 TS TAC TAC TAC (163) TS HE HE SW 6789 CQ INFO INFO FOS 6789 PC SECSYS SECSYS INFO1 6789 TS SECSYS SECSYS INFO2 9009 PC BMS BMS BMS1 My result set must eliminate the duplicate identifiers regardless of whoever we choose of the result set. (I mean without distinction Org, DF, s, Sub-s). My expected result set should be.
ID DSB DF SEC Sub-Sec (163) CQ CPDM CPDM HD 8888 TS TAC TAC TAC 6789 CQ INFO INFO FOS 9009 PC BMS BMS BMS1 Thank you
Orton
Hello
This sounds like a job for ROW_NUMBER:
WITH got_r_num AS
(
SELECT id, DSB, df, s, sub_sec org
ROW_NUMBER () OVER (PARTITION BY ID.
ORDER BY org
) AS r_num
OF view_x
)
SELECT id, DSB, df, sub_sec s,
OF got_r_num
WHERE r_num = 1
;
He is a Top - N query example, where you choose the elements of N (N = 1 in this case) from the top of an ordered list.
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) to your sample data and the results desired from these data. (I know that you said that you were a view selection. Just for this thread, pretending it is a picture and post simple CREATE TABLE and INSERT statements to simulate your point of view).
Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places. (I didn't quite understand the explanation above. I don't know why you want toID ORG DF DRY SUB_SEC
-- --- -- --- -------
1234 CQ DPRK DPRK HD
and is not
1234 IS CQ ASIC, ASIC
or
TS 1234 IT IT SW
or
1234 CQ ASIC ASIC HD
)
If you change the query at all, post your modified version.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002
-
small request I have given as below,
Month ProductNo CustomerNo units
9001 1001 Jan - 09 100
9002 1002 Jan - 09 200
9003 1003 Jan - 09 300
Jan 9001 400 ABCCustomer
9002 1004 Jan - 09 500
for all record - if column - customerNo starts with digital it must show as CN_ * other wise of the same name.
Result must be
9001 100 CN_1001-09 Jan
9002 200 CN_1002-09 Jan
9003 300 CN_1003-09 Jan
Jan 9001 400 ABCCustomer
9002 500 CN_1004-09 Jan
Can help get the queryA logic that is easier to implement this is as below
SQL> with t as (select 'jan' Month, 9001 ProductNo,'1001-09' CustomerNo,100 Units from dual union all 2 select 'jan', 9002, '1002-09', 200 from dual union all 3 select 'jan', 9003, '1003-09', 300 from dual union all 4 select 'jan', 9001, 'ABCCustomer', 400 from dual union all 5 select 'Jan', 9002, '1004-09', 500 from dual) 6 select month,productno,case when upper(substr(customerno,1,1))=lower(substr(customerno,1,1)) 7 then 'CN_'||customerno else customerno end customerno,units from t; MON PRODUCTNO CUSTOMERNO UNITS --- ---------- -------------- ---------- jan 9001 CN_1001-09 100 jan 9002 CN_1002-09 200 jan 9003 CN_1003-09 300 jan 9001 ABCCustomer 400 Jan 9002 CN_1004-09 500
TRY WITH THIS upper (substr(customerno,1,1)) = lower (substr(customerno,1,1))
-
Hi, unable to do any development in LR because of the message 'develop Module is disabled"can someone please get back to me as soon as possible to help turn the Module development...!
You use a MAC or a Windows computer?
Also mention the version of Lightroom you use
~ Assani
-
need help with the query, thx
Hello
I need a little help with the query I have to write;
the table has 4 columns:
what I am asking is the following result: salary according to the latest available yearcol1 col2 col3 col4 emp_name empl_id salary year content of data: col1 col2 col3 col4 smith 12 1200 1999 smith 12 1340 2000 smith 12 1500 2001 jones 13 1550 1999 jones 13 1600 2000 aron 14 1200 2002
i.e.
ID appreciate some guidance on how to achievesmith 12 1500 2001 jones 13 1600 2000 aron 14 1200 2002
Thank you
Rgdsselect *from (select col1, col2,col3, col4,row_number() over(partition by col1 order by col4 desc) rn from
) where rn=1
Maybe you are looking for
-
Searched a bit, but couldn't find an answer. When to use the express VI 'Write in a file as' and add comments to the data, it appears fine in excel (such as a column of additional next to data channels), but I don't see a way to display them in Diad
-
MFP 577: Error scanning file MFP 577
My MFP 577 ceased to be able to check the access to my computer to scan. I have not changed any settings or passwords. I tried to set up a new backup to the network folder in order to test, and it still does not work. I have reset router, rebooted
-
BIOS, do not recognize the legacy
I have a laptop of E1-572-5870. It had Windows 7 Home premium House on it. I had a discussion with one of your technicians that was not helpful. It was to send my laptop old days in a repair center in Texas. This isn't a good solution to say to your
-
Currently on unity 3.1.5 Got the unit 4 upgrade dvd Who can I call to register software, download the license etc. file since it will no longer the dongle... Im trying to look through the documentation but do not see a place to call. Help please
-
Dynamic content on the 2nd landing page (confirmation page)
I read a few posts, but the explanations were not very clear to me, so looking for direct help.I have an email which redirects the customer to a landing with a form page. The dynamic content on this page works as expected.By submitting the form, the