Query, which returns lines adding up to a value in a column
Hello
You are looking for an application that will process and return only the many lines that add up to a special value on a column value.
for example
ID name date_joined allocated salary
-- ------ --------------- ------- ------------
1 Tom January 1, 2010 1000 5000
Dave 2 3000 5000 February 1, 2010
3 Cindy 1000 5000 01-apr-2010
4 Ian 01-mar-2010 1000 5000
5 Matt 10 -jan-2010 1000-5000
Return the lines where wages adding upto or beyond the value allocated to 5000, order by date_joined or more former employee first.
The query should return:
ID name date_joined allocated salary
-- ------ --------------- ------- ------------
1 Tom January 1, 2010 1000 5000
2 Matt 10 -jan-2010 1000-5000
3 Ian 01-mar-2010 1000 5000
Dave 4 3000 5000 February 1, 2010
We do not want to deal with or include other lines summarizing calculation, would instead add first, if deficit adds to the line.
Tried with lead, windowed with range UNLIMITED etc. that PRECEDES, that would not come up with good logic.
I could make it work with PL/SQL, but do it in SQL turns out to be delicate.
Thank you.
A.
Thanks for the input guys.
Here, the ask is:
1. how to treat only as lines that satisfy the "allocated" value, without treatment of all lines.
> Thanks to Jarkko year John for the right direction.
> RanitB thank you for your approach to the application of the model, I am not well versed with model query that I'll get to. But for the moment its not useful for me.
2. to get only as much lines that are either less than or equal to 'assigned' value or satisfy "allocated", from less than "attributed" just beyond "allocated".
(Sorry for the language, if its not very clear, I do not know how this fits better, following example should help demonstrate).
I came up with the following code, although there could be best way to do it, I hope to see someone.
{code: sql}
create table t:
Select object_name, join_dt, the salary of 1000 last_ddl_time, allocated 5500
of object;
Select
/ * gather_plan_statistics * / *.
Of
(select
object_name, join_dt, salary, allocated, sofar, lag (sofar, 1, 0) over (order by join_dt) lag_sofar
Of
(select
object_name, join_dt, salary, allocated,
Salary on sofar (order by no_lig)
Of
(select object_name, join_dt, salary, allocated, row_number() on no_lig (order of join_dt) t) t - must do it has several join_dt even inputs (objects have same time ddl)
)
)
where
allocated > lag_sofar;
OBJECT_NAME | JOIN_DT | SALARY | ALLOCATED | SOFAR | LAG_SOFAR | |
---|---|---|---|---|---|---|
SDO_TOPO_GEOMETRY | 17 JULY 02 |
1000 |
5500 | 1000 | 0 | |
SI_AVERAGECOLOR | 18 JULY 02 | 1000 | 5500 | 2000 | 1000 | |
SI_COLORHISTOGRAM | 18 JULY 02 | 1000 | 5500 | 3000 | 2000 | |
SI_POSITIONALCOLOR | 18 JULY 02 | 1000 | 5500 | 4000 | 3000 | |
SI_FEATURELIST | 18 JULY 02 | 1000 | 5500 | 5000 | 4000 | |
SI_STILLIMAGE | 18 JULY 02 | 1000 | 5500 | 6000 | 5000 |
{code}
Sorry for the bad formatting, I tried couple of code integration/formatting of tags, but could not get formatting just as many of you have done above.
Can someone point me on the document where the tags for this type of formatting is present?
For now I am marking my question as answered with my own response and that of the other answers as useful.
If I get a better approach/solution I would mark it as correct.
Tags: Database
Similar Questions
-
Return the first line with a non-null value in a column
Hey there, gurus. Can someone give me a hand with this?
I have a table with six columns: Class_ID, Course_ID, start_date, Last_Name, First_Name, company. When our students take a class and will fill in an evaluation form, they fill in the Class_ID Last_Name First_Name, and Company. The Course_ID and Start_Date are filled automatically based on the Class_ID.
I am trying to generate a report that contains Class_ID, Course_ID and Start_Date, PLUS the value of the first not null in the column of company for a combination given to the three first columns. Here is my SQL that does not quite do the trick:
Select distinct c.class_id, c.course_id, c.start_date, p.company
class c, person p, student s
where substr (c.course_id, 1, 3) = "OBI".
and c.start_date > = SYSDATE-30
and c.class_id = s.class_id
and s.pid = p.pid
order start_date, company, class_id, course_id
At present, if in a given class, a student entered "CCCC" under the name of the company and another entry "Collin Co Comm Coll" and another between "Collin College", I would get three rows of this class when you use the SQL above. I want just one line. I don't really like which company names gets selected - one of them will be great for our needs. I just need to see a line for each class_id and single value that some students entered the area of the company. And I guess I have to say that if no student fills in the name of the company I need to see the value null, because I need to see the line no matter what.
Looks like some sort of funky outer join or a coalesce, but it is beyond my ability to understand.
Now I get this:
During class 1234 SQL271 Date 22/07/2013 company XYZ Inc.
Made up of class 1234 SQL271 Date 22/07/2013 company XYZ
1234 SQL271 Date 22/07/2013 company XYZ, class
What I want:
Class 1234 SQL271 22/07/2013 Date course XYZ Inc. or one of the other 2
Thanks in advance!select c.class_id, c.course_id, c.start_date, max(p.company) company from class c, person p, student s where substr(c.course_id,1,3) = 'OBI' and c.start_date >= SYSDATE-30 and c.class_id = s.class_id and s.pid = p.pid group by c.class_id, c.course_id, c.start_date order by class_id, start_date, course_id
Or if you want to list all businesses, you can use LISTAGG if you're on the latest version of ORACLE
-
How to display the number of lines of time giving the values of the columns?
Hi all
I want to display the number of rows times the value exists in the column num in the query below
Published by: Nag Aswadhati on November 1, 2012 12:34with t AS ( SELECT 'venkatesh' NAME, 'hyd' LOC, 2 NUM FROM DUAL UNION ALL SELECT 'prasad' NAME, 'hyd' LOC, 3 NUM FROM DUAL UNION ALL SELECT 'krishna' NAME, 'hyd' LOC, 1 NUM FROM DUAL ) SELECT T.* FROM T CONNECT BY ROWNUM <= NUM Expected output: venkatesh hyd 2 venkatesh hyd 2 prasad hyd 3 prasad hyd 3 prasad hyd 3 krishna hyd 1
Aswadhati NAG wrote:
Hi allI want to display the number of rows times the value exists in the column num in the query below
Expected output: venkatesh hyd 2 venkatesh hyd 2 prasad hyd 3 prasad hyd 3 prasad hyd 3 krishna hyd 1
With the help of connection by: -.
with t AS ( SELECT 'venkatesh' NAME, 'hyd' LOC, 2 NUM FROM DUAL UNION ALL SELECT 'prasad' NAME, 'hyd' LOC, 3 NUM FROM DUAL UNION ALL select 'krishna' name, 'hyd' loc, 1 num from dual ) select t.name, t.loc from t connect by level <= num and name = prior name and (prior sys_guid() is not null); NAME LOC --------- --- krishna hyd prasad hyd prasad hyd prasad hyd venkatesh hyd venkatesh hyd 6 rows selected
-
The line formatting based on the value of a column
Hi friends
I'm trying to format the entire row based on the value of the first column in my answers.
Example, if the first value of column 'F' now, I want the row to be colorful
I can do a conditional formatting on a column, but I want to do down the line
F 8.1% 12.0%
------------------------------------------
E 5.2% 3.5%
------------------------------------------
M 2.3% 3.3%
------------------------------------------
If one has done this or suggestions please answer
Thank you
Sang AWell, the conditional formatting can be done in PivotTables until the next version, 11g. In the meantime, you two options:
(1) http://gerardnico.com/weblog/2009/04/06/obiee-cross-conditional-formatting-on-a-pivot/
(2) http://oraclebizint.wordpress.com/2008/04/29/oracle-bi-ee-101332-conditional-formatting-based-on-multiple-character-columns-in-a-pivot-table/
(3) you can use your custom column filter functionality to get your ' sales in year 20xx "and a presentation to make this dynamic variable. So you can declare an array and use the method I described above.
Good luck.
-
create table ab (a number, b varchar2 (20));
Insert into ab
Select rownum, rownum. "" sample "
of the double
connect by level < = 10
create table bc (a number, b varchar2 (20));
Insert into BC.
Select rownum + 1, rownum + 1 | "" sample "
of the double
connect by level < = 10
Select * AB
where b in (select b BC where b = "2sample")
This query will return me 1 row, but there are cases where the value of the parameter b is null
and that it should return all rows in the table
as
Select * AB
where b in (select b BC where b = "2sample")
which return specific values, but I want to change in a way when the inner query returns nothing then outer query should return all the lines and works as
Select * AB;
Is it possible to put in a single query
Hello
You seem to ask for different things. You want all the lines AB when
- The parameter ("2sample' in the example) is NULL, or when
- There is no corresponding row in the 2 tables (which could happen even if the parameter is not NULL)
?
Assuming you want the option 2, here's one way:
WITH got_rnk AS
(
SELECT ab.*
DENSE_RANK () (ORDER IN CASE
WHEN b (IN)
SELECT b
BC.
WHERE b = "2sample" - parameter
)
THEN "A".
OF ANOTHER 'B '.
END
) AS rnk
AB
)
SELECT a, b
OF got_rnk
WHERE rnk = 1
;
This does not assume b is unique in each table.
Thanks for posting the CREATE TABLE and INSERT statements; It is very useful.
-
Subselect query returns "invalid identifier", but the nested query return lines
I don't think it's a general SQL question.
Select * from persons where person_id in)
Select person_id with people whose name = 'Obama' - subquery
) and age > 18;
When I run the subquery, I get:
ORA-00904: "PERSON_ID": invalid identifier
00904, 00000 - '% s: invalid identifier '.
* Cause:
* Action:
Error on line: column 5: 8
This is because the table people do not have the person_id field.
But when I run the nested together query it returns all the lines in people with the AGE greater than 18.
How is he succeeds when the subquery is obviously wrong?
363f652b-263D-4418-933F-74a1d0a41b4c wrote:
I don't think it's a general SQL question.
Select * from persons where person_id in)
Select person_id with people whose name = 'Obama' - subquery
) and age > 18;
When I run the subquery, I get:
ORA-00904: "PERSON_ID": invalid identifier
00904, 00000 - '% s: invalid identifier '.
* Cause:
* Action:
Error on line: column 5: 8
This is because the table people do not have the person_id field.
But when I run the nested together query it returns all the lines in people with the AGE greater than 18.
How is he succeeds when the subquery is obviously wrong?
Yes - this is a general SQL question and ask often enough.
Correlated subqueries depend on the inner query, be able to see and access to the columns of the outer query. Normally see you referenced in the WHERE clause of the subquery and not in the SELECT clause, but the reference is valid in both places. This works because the columns of the tables in the main query are accessible in the subquery. "Person_id" is probably a column in the table 'people '.
Which can be a cause of problems 'odd' when the column (in your case "person_id") is more of a table.
Use an alias in the subquery in the subquery and you will find that it will not succeed.
See these two articles AskTom where he addresses this specific issue
http://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:3317493900346468494
http://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:155200640564
-
PL/SQL Query return function, adding the column links
Hi all
I'm working on a SQL report with the area type = function from PL/SQL Query to return
All columns are generated dynamically based on my mapping table and a column of ID.
So whenever the page is loaded, according to the ID mapping table returns a set of columns in a particular order.
So not only the columns are dynamic, but the order of the columns varies also.
But the first 1 column is standard (it doesn't come from the mapping table) and is coded in my pl/sql block hard.
I'm fighting with the addition of a link to this column. The link must be a Javascript function which takes the parameters in the form of 2 columns in the mapping table.
My pl/sql block is something like that...
Now, I'm not able to transmit the values of this #map_id # and #comments # correctly. I tried so many different combinations of channels, but could not make it work.v_select := 'SELECT <g href=javascript:f_report1(#map_id#,#comments#)><img src=""></a> as report1, '; // g=a v_cols := 'contains all columns from the mapping table based on a ID(hidden item)'; v_from := 'FROM table'; v_where := 'where condition is put in here'; v_query := v_select||v_from||v_where; return v_query;
I'm not sure that the order of this map_id and commentscolumn and therefore cannot connect through the report attributes.
How can I go to a column value to the function?
Thank you
DippyThis should work if all goes well:
v_select := q'[ SELECT '' as chart, ]';
Published by: Dimitri Gielis on May 20, 2010 20:10
-
Need a query to return the first and last date for a rowset.
Hello
I have a query which can be simplified to the following data, if
Assume that it is my dataset, with THE_VALUE of
Sign (Anum) therefore,-1, 0 or 1.
* (Sorry for crushed registration. "I can't understand this website's rich text formatting.) *
THE_VALUE THE_DATE THE_MEMBER
1 0 1 January 2007
1 0 1 February 2007
1 0 1 March 2007
1. 1 April 1, 2007
1 1 1 May 2007
1 0 1 June 2007
1. 1 July 1, 2007
1. 1 August 1, 2007
1 0 01 - sep - 2007
2 0 1 January 2007
2 1 February 1, 2007
2 0 1 March 2007
2. 1 April 1, 2007
2 1 1 May 2007
2 0 1 June 2007
-2 1 1 July 2007
2. 1 August 1, 2007
2. 1 01-sep-2007
3 0 1 January 2007
3. 1 February 1, 2007
3 0 1 March 2007
3 0 1 April 2007
3. 1 May 1, 2007
3 0 1 June 2007
3. 1 July 1, 2007
3. 1 August 1, 2007
3 0 01 - sep - 2007
I need to get the lines with the THE_MEMBER, the values of the first and the last
THE_DATE, where the value is - 1, and the date range is the last
set of lines to the Member, with the same value of THE_VALUE.
I tried the following to get the dates of first and last for a set
consecutive months with the same value for the Member.
SELECT the_member
the_value
the_date
first_value (the_date)
in the first_date (PARTITION the_member, ORDER BY the_member the_value, the_date)
last_value (the_date)
during the last_date (PARTITION the_member, ORDER BY the_member the_value, the_date)
OF togola
ORDER BY the_member
the_date;
At first, it seems to work, but then, when the return value
an old value, FIRST_DATE will be the first of all the lines containing
This value for the Member rather than the first of consecutive
rows with this value for the Member. Apparently the partitioning
occurs before the order.
THE_MEMBER THE_VALUE THE_DATE FIRST DATE LAST DATE
1 0 January 1, 2007 January 1, 2007 January 1, 2007
1 0 1 February 2007 1 January 2007 1 February 2007
1 0 1 March 2007 1 January 2007 March 1, 2007
1. 1 April 1, 2007 April 1, 2007 April 1, 2007
1. 1 May 1, 2007 April 1, 2007 may 1, 2007
1-0 June 1, 2007 January 1, 2007 June 1, 2007
1. 1 July 1, 2007 April 1, 2007 July 1, 2007
1. 1 August 1, 2007 April 1, 2007 August 1, 2007
1 0 01 - sep - 2007 1 January 2007 01-Sep-2007
2 0 January 1, 2007 January 1, 2007 January 1, 2007
2 1 1 February 2007 February 1, 2007 February 1, 2007
2 0 1 March 2007 1 January 2007 March 1, 2007
2. 1 April 1, 2007 February 1, 2007 April 1, 2007
2 1 1 May 2007 February 1, 2007 may 1, 2007
2-0 June 1, 2007 January 1, 2007 June 1, 2007
-2 1 1 July 2007 February 1, 2007 July 1, 2007
2. 1 August 1, 2007 February 1, 2007 August 1, 2007
2. 1 01-sep-2007 1 February 2007 01-Sep-2007
3 0 January 1, 2007 January 1, 2007 January 1, 2007
3. 1 February 1, 2007 February 1, 2007 February 1, 2007
3 0 1 March 2007 1 January 2007 March 1, 2007
3 0 April 1, 2007 January 1, 2007 April 1, 2007
3. 1 May 1, 2007 February 1, 2007 may 1, 2007
3 0 June 1, 2007 January 1, 2007 June 1, 2007
3. 1 July 1, 2007 February 1, 2007 July 1, 2007
3. 1 August 1, 2007 February 1, 2007 August 1, 2007
3 0 01 - sep - 2007 1 January 2007 01-Sep-2007
That's what I need to get in the end.
THE_MEMBER FIRST DAY DATE OF LAST
July 2 1 2007-01 - Sep - 2007
Any ideas would be really appreciated.
Published by: user10700981 on December 17, 2008 13:57Hello
We'll call the lines whose the_value =-1 'good' lines and lines with the_value! =-1 ranks of 'bad '.
For each value of the_value, we need the first and last values of the_date where
the last row in the group is good
(b) the current line is good
(c) there is a lot of lines from the current line to the end of the Group
Condition (a) is just a special case of (c).
Conditions (b) and (c) are similar: (b) if applied to the current line, (c) applies to all lines after him. They can easily be combined into a single test that counts the number of lines after the current line or bad.Which produces the results you requested of the sample data that you provided:
WITH count_bad AS ( SELECT the_member , the_date , COUNT ( CASE WHEN the_value != -1 -- assuming the_value is never NULL THEN 1 END ) OVER ( PARTITION BY the_member ORDER BY the_date DESC ) AS bad_cnt FROM table_x ) SELECT the_member , MIN (the_date) AS first_date , MAX (the_date) AS last_date FROM count_bad WHERE bad_cnt = 0 GROUP BY the_member ORDER BY the_member;
-
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?
-
Query Union returns the correct data x 2
I have a union query that returns 2 identical lists of data. The data are correct, but I can't work on why it is duplicated. Can anyone help? Thank you.
John
****************************
set linesize 400
set pagesize 9999
NewPage Set 1
wrap off Set
break off Set
Set of feedback on
set the file name = CATS_TURBO_all_LiveT
coil & filename
Noprint today new_value DATEVAR COLUMN
COLUMN case_id FORM 999999 TITLE 'fault '.
COLUMN product_name FORMAT a10 HEADING 'node '.
COLUMN priority_type_name format a4 POSITION "PRI."
Report_date FORMAT of the COLUMN entitled date 'Date of Recvd'
Restore_date FORMAT of the COLUMN date TOPIC "restored".
Close_date FORMAT of the COLUMN date POSITION "closed".
COLUMN assigned_tech_id FORMAT a10 TITLE "GENIUS".
COLUMN status_type_name FORMAT a3 DIRECTION "FS".
Header of COLUMN name format a4 'Type '.
Header of COLUMN Champ_1 format a20 'Exchange '.
COLUMN sla_name format a12 direction "platform".
Format COLUMN header generic a4 "Gen."
COLUMN question_text format a90 titled "Error Description".
COLUMN note_text a90 format called 'progress '.
TTITLE left 'report ' -.
Center ' TURBO all flaws (& filename... SQL) "-"
Jump STRAIGHT DATEVAR-
Left ' wait > > ' jump 1
Select distinct
a.case_id "Fault."
c.product_name
, decode (f.priority_type_name, 'Low', '4', 'Medium', '3', 'High', '2', 'Urgent', '1') Pri
, to_char (a.report_date, ' DD/MM/YYYY HH24') "received".
, to_char (' a.restore_date, ' DD/MM/YYYY HH24 ")"restored ".
, to_char (a.close_date, ' DD/MM/YYYY HH24') 'closed '.
, decode (d.name, 'Software', from ", 'Hardware', 'H', 'Firmware', 'F', 'Unknown', 'U', 'General', 'Gen', 'Doc', 'Doc', 'n' and"No. Fault"") 'Type '.
, decode (b.status_type_name, ' closed - resolved ', '02', 'Pending', '40', 'On Hold - waiting for approval', '41 ', 'pending', '41', 'Wait-Service restored', ' 41', 'lack of training', '44', 'Telesys survey fault', '44') FS
g.field_1
e.sla_name
, decode (a.assigned_tech_id, '10', 'JSMITH', '09', 'MBROWN', '07', 'SCHATTER', '08', 'RSMEED' ', '12', ' SCHOYM') 'B '.
, to_char (sysdate, 'DD-MON-YYYY HH24') today
, to_char (translate (dbms_lob.substr(a.question_text,100), CHR (13) |)) CHR (10), CHR)
question_text 32)))
, null "Note".
of oracledb.incident one
oracledb.status_type b
c oracledb.item_type
oracledb.problem_type d
e oracledb.sla
oracledb.priority_type f
oracledb.item g
oracledb.incident_note h
where (a.status_type_id = b.status_type_id)
and (a.product_id = c.product_id)
and (a.problem_type_id = d.problem_type_id)
and (a.sla_id = e.sla_id)
and (a.priority_type_id = f.priority_type_id)
and (a.product_id = g.product_id)
and e.sla_name = "TURBO PÉI"
and g.field_1 not in the (' SysCntl-1', ' SysCntl-2', "TURBO PÉI" "")
and a.case_id = h.case_id (+)
and not exists (select case_id from k oracledb.incident_note where k.case_id = a.case_id)
and a.deleted <>' 1'
Union
Select distinct
a.case_id "Fault."
c.product_name
, decode (f.priority_type_name, 'Low', '4', 'Medium', '3', 'High', '2', 'Urgent', '1') Pri
, to_char (a.report_date, ' DD/MM/YYYY HH24') "received".
, to_char (' a.restore_date, ' DD/MM/YYYY HH24 ")"restored ".
, to_char (a.close_date, ' DD/MM/YYYY HH24') 'closed '.
, decode (d.name, 'Software', from ", 'Hardware', 'H', 'Firmware', 'F', 'Unknown', 'U', 'General', 'Gen', 'Doc', 'Doc', 'n' and"No. Fault"") 'Type '.
, decode (b.status_type_name, ' closed - resolved ', '02', 'Pending', '40', 'On Hold - waiting for approval', '41 ', 'pending', '41', 'Wait-Service restored', ' 41', 'lack of training', '44', 'Telesys survey fault', '44') FS
g.field_1
e.sla_name
, decode (a.assigned_tech_id, '10', 'JSMITH', '09', 'MBROWN', '07', 'SCHATTER', '08', 'RSMEED' ', '12', ' SCHOYM') 'B '.
, to_char (sysdate, 'DD-MON-YYYY HH24') today
, to_char (translate (dbms_lob.substr(a.question_text,100), CHR (13) |)) Chr (10), Chr (32))) question_text
, to_char (translate (dbms_lob.substr(h.note_text,100), CHR (13) |)) Chr (10), Chr (32))) note_text
of oracledb.incident one
oracledb.status_type b
c oracledb.item_type
oracledb.problem_type d
e oracledb.sla
oracledb.priority_type f
oracledb.item g
oracledb.incident_note h
where (a.status_type_id = b.status_type_id)
and (a.product_id = c.product_id)
and (a.problem_type_id = d.problem_type_id)
and (a.sla_id = e.sla_id)
and (a.priority_type_id = f.priority_type_id)
and (a.product_id = g.product_id)
and e.sla_name = "TURBO PÉI"
and g.field_1 not in the (' SysCntl-1', ' SysCntl-2', "TURBO PÉI" "")
and a.case_id = h.case_id
and h.note_id = (select max (i.note_id)
oracledb.incident_note I have
where a.case_id = i.case_id)
and a.deleted <>' 1'
order by 1;
/
SPOOL OFF
Clear jump
output
Published by: user13388553 on 11/24/2010 14:59If your code is that you run in the production data splits because you're runnign queries twice.
from oracledb.incident_note i where a.case_id = i.case_id) and a.deleted '1' order by 1; / SPOOL OFF
The semicolon after that command by 1 causes the statement to be executed, the slash on the next line causes the reexecute being. Delete one of them.
John
-
Doubt with query that returns unnecessary reocrds
Hello
I use under query to retrieve security descending titles in a database:
Select master sre1.security_id,
sre2. Clone SECURITY_ID, sa1. Addr STREET_ADDR1
Of
SAM_REAL_ESTATE sre1, SAM_REAL_ESTATE sre2, sam_address sa1, sa2 sam_address
where
sre1. ADDRESS_ID = sa1. ADDRESS_ID and sre2. ADDRESS_ID = sa2. ADDRESS_ID
and sre1.security_id < sre2. SECURITY_ID
and trim (nvl (upper (sa1. STREET_ADDR1), 'Null')) = trim (nvl (upper (sa2. STREET_ADDR1), 'Null'))
and in sre1.security_id (175459876,175460893,175460770,20530359,21943331,20306795)
and in sre2.security_id (175459876,175460893,175460770,20530359,21943331,20306795)
order by 1, 2;
which returns results as below:
MASTER CLONE ADDR
20306795 20530359 Waverley
20306795 21943331 Waverley
* 20530359 21943331 Waverley *.
175459876 175460770 temple
175459876 175460893 temple
* 175460770 temple 175460893 *.
Now, I do not want the selected records in bold as the safety of clone is coming security master while only the less registration by different address should enter into main list and the rest of his security should come clone
Please suggest
Thank you
DeepakNOT TESTED
select min(master) master,clone,addr from (select sre1.security_id master, sre2.SECURITY_ID clone, sa1.STREET_ADDR1 addr from SAM_REAL_ESTATE sre1, SAM_REAL_ESTATE sre2, sam_address sa1, sam_address sa2 where sre1.ADDRESS_ID = sa1.ADDRESS_ID and sre2.ADDRESS_ID = sa2.ADDRESS_ID and sre1.security_id < sre2.SECURITY_ID and trim(nvl(upper(sa1.STREET_ADDR1),'Null')) = trim(nvl(upper(sa2.STREET_ADDR1),'Null')) and sre1.security_id in(175459876,175460893,175460770,20530359,21943331,20306795) and sre2.security_id in(175459876,175460893,175460770,20530359,21943331,20306795) order by sre2.SECURITY_ID,upper(sa1.STREET_ADDR1),sre1.security_id ) group by clone,addr order by 1,2
Concerning
Etbin
It is not a Top - N query
Edited by: Etbin the 13.8.2009 12:00
-
Tabular returns lines based on the selection list
Howdy-
An element of the selection list is used to select a job title.
The tabular presentation returns lines of documents to be considered annually by the title of the post.
A single column in a tabular form (the number of the document) is defined as a link so that the user can open and read the document.
It works beautifully.
But...
Some job titles return a row of five documents, still others return more than a hundred, so when paging is used to move to the next set of lines in tabular form, updates the selection list and the selection is lost. I have the Page Action selection list element when the modified value to Redirect and set the value, but the Type of Source is static that may be my problem.
How can I use pagination while maintaining the value of the selection list?
Thanks in advance.
Alexandra
Request Express 4.2.2.00.11 (by the way, I don't have our network administrator do a update to this version?)
the value of the default selection on a hidden item list. When you select from the drop-down list, set the item also hid from the selected item.
-
How can we calll a package of Pro * C function, which returns a ROWTYPE?
Hi all
I did research on it, but have not met another example - maybe you can't do?
We have a function in a PL/SQL package on our database, which returns a value of type % ROWTYPE. We call it successfully from within our application (Oracle Forms), but we must also be able to call from a Pro * C program. Has anyone else done this successfully?
We use the Oracle 11 g, Pro * C 10.1.0.5.0 exit.
We have a function in a PL/SQL package on our database, which returns a value of type % ROWTYPE. We call it successfully from within our application (Oracle Forms), but we must also be able to call from a Pro * C program.
I guess you can do the following:
-call the function from an embedded PL/SQL block
-copy each of the Records of individual host variables attributes
EXEC SQL EXECUTE DECLARE my_rec my_table%rowtype; BEGIN my_rec := my_pkg.fun(); :attr1 := my_rec.col1; :attr2 := my_rec.col2; END; END-EXEC;
-
How to write a query to return rows with the varchar column that contains even a single occurrence of the characters, such as Ÿ and
I have a table whose columns with values such as
MINNEAŸPOLIS and ¿VV ¿A
Only the characters that are allowed in this column are alphabets, numbers, spaces, points and supports.
Please help to write a SQL SELECT with Regexp_like query or any other option.
Thanks to you all! Under query worked for me. Thank you Frank to explain the concept of hooks inside regexp_like.
SELECT * FROM testspecial, WHERE REGEXP_LIKE (sampletext, "[^] ^ A - Z ^ a - z ^ 0-9 ^ [^.]") ^ {^} ^]') ;
-
How do I rotate my result of a query from a line to a SQL column?
Hey, guys:
Is it possible that I can rotate my result of a query from a line to a SQL column?
It's a certain type of pivot example
Instead of
DEPTNO DNAME
-------- ---------------
10 accounting
It would be
DEPTNO: 10
DNOM: ACCOUNTINGHello
When you have N columns to rank 1 and you want to display in the form of 1 column on several lines, it's called Unpivoting . Here's a way to do it:
WITH cntr AS ( SELECT LEVEL AS n FROM dual CONNECT BY LEVEL <= 2 -- number of columns to be unpivoted ) SELECT CASE c.n WHEN 1 THEN 'DEPTNO' WHEN 2 THEN 'DNAME' END || ':' AS label , CASE c.n WHEN 1 THEN TO_CHAR (d.deptno) WHEN 2 THEN d.dname END || ':' AS val , d.deptno -- PK, if needed FROM cntr c CROSS JOIN scott.dept d WHERE deptno = 10 -- or whatever ;
The query above works in Oracle 9.1 or more.
From Oracle 11.1, you can also use the SELECT... Function of the UNPIVOT operator.
Maybe you are looking for
-
Impossible to reinstall imovie
First of all, I deleted imovie since I had problems with the update. Now that I try to reinstall, my app store confirms that I deleted the application. He just constantly says "update". When I try to press the update, it shows the wheel is turning, b
-
Error 1638 during the 'updating' Skype for Windows 8
OK, so I go through the installation instructions as when you open Skype it says updated. When you run through it then that you request to close Skype. After doing that I get these messages coming up on top of the screen: The first screen that appear
-
Pre3 stops working after Web OS 2.2 update
Hello Please can you help. I just went through the update of web os 2.2 and the phone does not work correctly. How to revert to the version that the phone came with this worke ok. I did the upgrade of air and the webosdoctor, eneven got that work on
-
Satellite M70 - 122 memory module attachment
Evening! Can I attach the memory module 1 GB DDR2 PC2-4300 on my laptop Satellite M70-122 by myself and maybe there's a certain manual for such action?
-
2013 runtime environment and Application Builder
I built executables using the addon builder application. There is no appeal to an external dll, etc. I've had several co-workers install updated runtime on their machines, but they may not always run the executables. Machines were restarted, stand