Largest and 2nd largest number query group by clause doubt
Hi, I have the following data in the database
deal id reporting date
12 6/1/2012
12 4/1/2012
12 2/1/2012
13 3/1/2012
13 2/1/2012
13 1/1/2012
I want for each deal id , the highest reporitng date and the 2nd highest reporting date...
i.e output
deal id date1 date2
12 6/1/2012 4/1/2012
13 3/1/2012 2/1/2012
I wrote the following query
select dealID,reportingDate from XYZ ,(select deal id , max(reportingDate)as d1 from XYZ) B
where
dealId=b.dealID
and reportingDate!=b.d1
order by reportingDate desc
the problem is it gets all reporting date but the highest one for each deal ID. I do not want all the dates to come. just the highest and second highest
plz help
Edited by: user7963410 on Sep 14, 2012 10:01 PM
Venkadesh wrote:
this ?This is one overcomplicated piece of code. And it is incorrect. First of all '6/1/2012' is a string, not a date, so ordering by it will produce incorrect results. For example (I assume '6/1/2012' is Januray 6, 2012), '6/1/2012' > '1/5/2012':
SQL> with t(id,reporting) as
2 (
3 select 12,'6/1/2012' from dual
4 union all
5 select 12,'4/1/2012' from dual
6 union all
7 select 12,'1/5/2012' from dual
8 union all
9 select 13,'3/1/2012' from dual
10 union all
11 select 13,'2/1/2012' from dual
12 union all
13 select 13,'1/1/2012' from dual
14 )
15 select id,regexp_substr(reporting,'\d+.\d+.\d+') date1,
16 regexp_substr(reporting,'\d+.\d+.\d+',1,2) date2
17 from (select id,listagg(reporting,' ') within group(order by reporting desc)
18 reporting from (select id,reporting
19 from (select id,reporting,row_number() over(partition by id order by reporting desc) rn
20 from t)
21 where rn<=2)
22 group by id)
23 /
ID DATE1 DATE2
12 6/1/2012 4/1/2012
13 3/1/2012 2/1/2012
SQL> And code doesn't take into account id,reporting might have duplicates:
SQL> with t(id,reporting) as
2 (
3 select 12,'6/1/2012' from dual
4 union all
5 select 12,'6/1/2012' from dual
6 union all
7 select 12,'4/1/2012' from dual
8 union all
9 select 12,'2/1/2012' from dual
10 union all
11 select 13,'3/1/2012' from dual
12 union all
13 select 13,'2/1/2012' from dual
14 union all
15 select 13,'1/1/2012' from dual
16 )
17 select id,regexp_substr(reporting,'\d+.\d+.\d+') date1,
18 regexp_substr(reporting,'\d+.\d+.\d+',1,2) date2
19 from (select id,listagg(reporting,' ') within group(order by reporting desc)
20 reporting from (select id,reporting
21 from (select id,reporting,row_number() over(partition by id order by reporting desc) rn
22 from t)
23 where rn<=2)
24 group by id)
25 /
ID DATE1 DATE2
12 6/1/2012 6/1/2012
13 3/1/2012 2/1/2012
SQL> Anyway, all we need is row_number and max:
select id,
reporting date1,
prev_reporting date2
from (
select id,
reporting,
row_number() over(partition by id order by reporting desc) rn,
max(reporting) over(partition by id order by reporting range between unbounded preceding and 1/24/60/60 preceding) prev_reporting
from t
where rn = 1
/For example:
with t(id,reporting) as
select 12,to_date('6/1/2012','dd/mm/yyyy') from dual
union all
select 12,to_date('6/1/2012','dd/mm/yyyy') from dual
union all
select 12,to_date('4/1/2012','dd/mm/yyyy') from dual
union all
select 12,to_date('2/1/2012','dd/mm/yyyy') from dual
union all
select 13,to_date('3/1/2012','dd/mm/yyyy') from dual
union all
select 13,to_date('2/1/2012','dd/mm/yyyy') from dual
union all
select 13,to_date('1/1/2012','dd/mm/yyyy') from dual
select id,
reporting date1,
prev_reporting date2
from (
select id,
reporting,
row_number() over(partition by id order by reporting desc) rn,
max(reporting) over(partition by id order by reporting range between unbounded preceding and 1/24/60/60 preceding) prev_reporting
from t
where rn = 1
ID DATE1 DATE2
12 06-JAN-12 04-JAN-12
13 03-JAN-12 02-JAN-12
SQL> But I prefer:
select id,
reporting date1,
Nth_highest_reporting date2
from (
select id,
reporting,
row_number() over(partition by id order by reporting desc) rn,
lead(reporting,:n - 1) over(partition by id order by reporting desc) Nth_highest_reporting
from (
select distinct *
from t
where rn = 1
/Where :n is Nth highest. For example:
SQL> variable n number
SQL> exec :n := 2;
PL/SQL procedure successfully completed.
SQL> with t(id,reporting) as
2 (
3 select 12,to_date('6/1/2012','dd/mm/yyyy') from dual
4 union all
5 select 12,to_date('6/1/2012','dd/mm/yyyy') from dual
6 union all
7 select 12,to_date('4/1/2012','dd/mm/yyyy') from dual
8 union all
9 select 12,to_date('2/1/2012','dd/mm/yyyy') from dual
10 union all
11 select 12,to_date('1/1/2012','dd/mm/yyyy') from dual
12 union all
13 select 13,to_date('3/1/2012','dd/mm/yyyy') from dual
14 union all
15 select 13,to_date('2/1/2012','dd/mm/yyyy') from dual
16 union all
17 select 13,to_date('1/1/2012','dd/mm/yyyy') from dual
18 )
19 select id,
20 reporting date1,
21 Nth_highest_reporting date2
22 from (
23 select id,
24 reporting,
25 row_number() over(partition by id order by reporting desc) rn,
26 lead(reporting,:n - 1) over(partition by id order by reporting desc) Nth_highest_reporting
27 from (
28 select distinct *
29 from t
30 )
31 )
32 where rn = 1
33 /
ID DATE1 DATE2
12 06-JAN-12 04-JAN-12
13 03-JAN-12 02-JAN-12
SQL> exec :n := 3;
PL/SQL procedure successfully completed.
SQL> /
ID DATE1 DATE2
12 06-JAN-12 02-JAN-12
13 03-JAN-12 01-JAN-12
SQL> exec :n := 4;
PL/SQL procedure successfully completed.
SQL> /
ID DATE1 DATE2
12 06-JAN-12 01-JAN-12
13 03-JAN-12
SQL> SY.
Similar Messages
-
HOw Do I count and identify the number of groups in a groups output.
I have a query that reads like this..
SELECT s.spec_Sort,s.spec_ID, s.spec_Name, b.bus_Name,
b.bus_ID
FROM (tbl_businesses as b INNER JOIN tbl_SpecBusRel as sb ON
b.bus_ID = sb.specbus_busid) INNER JOIN tbl_specialties as s ON
sb.specbus_specid = s.spec_ID
ORDER BY s.spec_Sort, b.bus_Name
and then I am outputing like this...
<cfoutput query="rsGetSpecialties" group="spec_Name">
<cfif THIS IS WHAT I
NEED)></td><td></cfif>
<h2><a class="specialty" href="javascript;"
onclick="dwfaq_ToggleOMaticDisplay(this,'#spec_ID#');return
document.MM_returnValue">#spec_Name#</a></h2>
<div id="#spec_ID#" style="display:none">
<cfoutput><p><a
href="#request.details#?bus_ID=#bus_ID#">#bus_Name#</a></p></cfoutput>
</div>
</cfoutput>
This displays in this manner...
Specialty
dealer
Specialty
dealer1
dealer2
Etc...
What I am trying to do is find out how many specialties there
are, figure out where the middle is so I can insert a new table
data cell and start a new column.
Basically - two columns with the data divided in half by
specialty NOT by the number of dealers.
I hope that makes sense. Of course I am trying to do it w/ as
little query action as possible. My only solution may be to have
more than one query and the second only finds a list of the
sepcialties that contain the dealers and then find the middle one
and simply say if current specialty = middleSpecialty then start a
new column.
Thanks all,
ChrisThanks for the replies. I don't need the number of occurances
of each specialties - I simply need to know how many specialties
there are and then split them in half.
This may be the long way around -but it is what I did...
<cfquery name="rsGetSpecialties" >
SELECT s.spec_Sort,s.spec_ID, s.spec_Name, b.bus_Name,
b.bus_ID, b.bus_Pcity, b.bus_PState
FROM (tbl_businesses as b INNER JOIN tbl_SpecBusRel as sb ON
b.bus_ID = sb.specbus_busid) INNER JOIN tbl_specialties as s ON
sb.specbus_specid = s.spec_ID
ORDER BY s.spec_Sort, b.bus_Name
</cfquery>
<cfset specs = valuelist(rsGetSpecialties.spec_ID)>
<cfquery name="rsListSpecialties">
SELECT spec_ID,spec_Name
FROM tbl_specialties
WHERE spec_ID in(#specs#)
ORDER BY spec_Name
</cfquery>
<cfset middle = int(rsListSpecialties.recordcount/2)>
<cfset specs = valuelist(rsListSpecialties.spec_Name)>
<cfset middle = listgetat(#specs#,middle)>
then displayed like this...
<td valign="top" width="50%">
<cfoutput query="rsGetSpecialties" group="spec_Name">
<h2><a class="specialty" href="javascript;"
onclick="dwfaq_ToggleOMaticDisplay(this,'#spec_ID#');return
document.MM_returnValue">#spec_Name#</a></h2>
<div id="#spec_ID#" style="display:none">
<cfoutput><a
href="#request.details#?bus_ID=#bus_ID#">#bus_Name#
(#bus_PCity#, #bus_PState#)</a><br /></cfoutput>
</div>
*****This is the line that does the splitting *****
<cfif spec_Name EQ middle></td><td
valign="top" width="50%"></cfif>
</cfoutput>
</td>
As for removing the extraneous cfoutput --> I thought that
I needed that in order to show the material within the grouped
data. HOw does CF know what data to repeat and what data to not
repeat in a grouped output? I will have to look this one up some
more.
thanks for the help -
Need A Query (Group By Clause)
Dear All,
There is table having following structure
Reservation_code varchar2(10)
Cust_Type varchar2(10)
Cust_no varchar2(10)
Contrno varchar2(10)
subno number(20)
The data in table may have like this
Reservation_code cust_type ,cust_no ,contrno , subno
abc a a 10 501
abc a a 10 502
abc a a 10 504
abc a a 10 505
abc a a 10 506
abc a a 10 509
abc a a 10 511
Every column can be null except subno and we have to group remaining columns except subno
I want to insert data from this to another table like this
Reservation_code From_Subno To_subno Total_numbers
abc 501 502 2
abc 504 506 3
abc 509 509 1
abc 511 511 1
Mean i Need to Know the Starting SubNo for a Group Ending SubNo for a Group and Number of Rows in that Group.
I insert data successfully with help of two FOR LOOPS but it is very slow
Is there any other faster way to slove this problem.
Thanks in AdvanceDear All,
There is table having following structure
Reservation_code varchar2(10)
Cust_Type varchar2(10)
Cust_no varchar2(10)
Contrno varchar2(10)
subno number(20)
The data in table may have like this
Reservation_code cust_type ,cust_no ,contrno , subno
abc a a 10 501
abc a a 10 502
abc a a 10 504
abc a a 10 505
abc a a 10 506
abc a a 10 509
abc a a 10 511
Every column can be null except subno and we have to group remaining columns except subno
I want to insert data from this to another table like this
Reservation_code From_Subno To_subno Total_numbers
abc 501 502 2
abc 504 506 3
abc 509 509 1
abc 511 511 1
Mean i Need to Know the Starting SubNo for a Group Ending SubNo for a Group and Number of Rows in that Group.
I insert data successfully with help of two FOR LOOPS but it is very slow
Is there any other faster way to slove this problem.
Thanks in Advance -
Modes and Methods in Tag Query and SQL Query
Hi,
Can someone explain me about the modes available in <b>TAG Query and SQL Query.</b>
TAG Query has modes such as <b>Current, CurrentWrite, GroupList, History, HistoryEvent, ModeList, Statistics and TagList</b>
SQL Query i still have doubt on <b>FixedQuery with output , Modelist and TableList</b>
I also need to know why methods are used?
Thanks in advance
Regards
MuzammilI'll try to explain to the best of my knowledge :
<u><b>TagQuery</b></u>
<b>Current</b> : Gives you the current value of the Tag you are reading.
<b>CurrentWrite</b> : Let you write a Value as the Current Value of the Tag.
<b>GroupList</b> : Generally Tags are grouped under different groups. Returns you the name of the Groups.
<b>From the xMII Help Document :</b>
<b>History</b> : History Mode returns interpolated data. Interpolation can be accomplished by specifying either the # of rows desired or the retrieval resolution. If the mode is "History" and a value is provided for the Resolution parameter (which is in seconds), the connector will retrieve evenly-spaced values starting at the beginning of the time interval, up to the maximum # of rows specified in the RowCount parameter. If no value is provided for the Resolution parameter, the connector will return an evenly-spaced number of values based on the value of the RowCount parameter.
For example, if the time interval is 1 hour, Resolution is 15, and RowCount is 240, the connector will return evenly spaced values each 15 seconds, up to 240 values (which would span the entire hour).
If the time interval is 1 hour, Resolution is not provided or is set to zero, and RowCount is 120, the connector would return 120 evenly spaced values, at an effective interval of 30 seconds.
<b>HistoryEvent Mode</b> : The connector can provide historical values "as they were stored" the database. This mode provides no interpolation of values.
<b>Statistics Mode</b> : When retrieving data for statistical calculations, the connector utilizes the same techniques as in the "HistoryEvent" mode. It is important to note that the first two returning columns in the HistoryEvent query must be the timestamp and the value, in that order. The SAP xMII Statistical processor expects that order, or errors will occur. This ensures precision of statistical measurements, particularly time-weighted average, by using the exact storage time and values from the historical database. The SAP xMII system provides the statistical calculations.
<b>Modelist</b> : Basically returns the modes of the Query Available. The Data returned is same as the data in the Modes list in the Quert Template Editor.
<b>Taglist</b> : Returns all the Tags in the Datasource.
<u><b>SQL Query</b></u>
<b>Modelist</b> : Same as above.
<b>TableList</b> : List of all the tables in the database to which the connector connects.
Again from SAP xMII Help Documentation :
<b>FixedQueryWithOutput</b> : This mode is used to execute an Oracle stored procedure or function that returns a REF CURSOR as output. The position of the REF CURSOR is marked by a "?" in the query. For example:
<b>Create a table.</b>
<i>create table usage (id int, name varchar(50));
insert into usage (id, name) values (1, 'test1');
insert into usage (id, name) values (2, 'test2');
insert into usage (id, name) values (3, 'test3');
insert into usage (id, name) values (4, 'test4');
insert into usage (id, name) values (5, 'test5');
insert into usage (id, name) values (6, 'test6');
insert into usage (id, name) values (7, 'test7');
insert into usage (id, name) values (8, 'test8');</i>
<b>Define the stored procedure.</b>
<i>DROP PACKAGE foopkg;
CREATE PACKAGE foopkg IS
TYPE cursortype is ref cursor;
PROCEDURE test (mycursor in out cursortype);
END foopkg;
CREATE PACKAGE BODY foopkg IS
PROCEDURE test (mycursor in out cursortype) AS
BEGIN
open mycursor for select * from usage;
END;
END foopkg;
</i>
Define a query template for calling the stored procedure. Enter the following in the FixedQuery tab:
<b>call foopkg.test(?)</b>
This template returns all rows from the Usage table. -
Select columns not in group by clause
Hi Guys,
I want to fetch columns from a table which are not in group by clause. The catch here is that I also need a count and decode column..
SELECT col_A, col_B, decode(col_C, '10', '10', '26', '26', '00') col_CT, col_X, col_Y count(*) CNT
FROM TABLE_T
WHERE col_B IN (100,101,102) AND col_C IN ('44','45','10','26')
GROUP BY col_A, col_B, decode(col_C, '10', '10', '26', '26', '00')
ORDER BY col_CT
Since, col_X and col_Y are not in GROUP BY clause, it throws error. Also, decode/count of the columns makes it more complex.
Please help me on this.
Thanks,
AmyHi, Amy,
Welcome to the forum!
Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statments, relevant columns only) for all tables involved, and the results you want from that data.
Always say which versionof Oracle you're using.
How to do what youy want depends on what you want, which is unclear.
If you say "GROUP BY a, b, c", that means you only want one row of output for each distinct combination of a, b and c. How do x and y fit into that? Do you want a separate output row for each distinct combination of a, b,c, x and y? Then add x and y to the GROUP BY clause. If you don't want separate rows for each combinataion of x and y, what do you want when a group has more than 1 value for either of them?
You can simplify the code a little by doing the DECODE in a sub-query; then you can use the alias col_ct as many times as you like in the main query. That will make the code easier to maintain, too. -
Determining Largest and Smallest integers, without creating multiple ints
I created a program that reads a list of numbers (doubles) terminated by a sentinal value, and outputs the average. The do-while statement with the sentinal value termination uses only one specified integer, changed with the input of each new number. Now without specifying more integers is there a way i can determine the largest and smallest number on the list?
import java.util.*;
public class LabThree
public static void main(String[] args)
Scanner keyboard = new Scanner(System.in);
int totaldoubles, max, min;
double total, nextnum;
String answer;
do
System.out.println();
System.out.println("Enter a list of nonnegative integers");
System.out.println("When you are finished with the list, enter a negative number");
System.out.println();
System.out.println("I will tell you the largest and smallest integer");
System.out.println("and give you the average the list");
totaldoubles = 0 ;
total = 0;
nextnum = keyboard.nextDouble();
while (nextnum >= 0)
total = total + nextnum;
totaldoubles++;
nextnum = keyboard.nextDouble();
if (totaldoubles > 0)
System.out.println("The average is: " + (total/totaldoubles));
else
System.out.println("No scores to average");
System.out.println();
System.out.println("Do you want to average another list?");
System.out.println("Enter Yes or No");
answer = keyboard.next();
}while (answer.equalsIgnoreCase("yes"));
}Message was edited by:
thecynicle1
Message was edited by:
thecynicle1ok i tried this:
import java.util.*;
public class LabThree
public static void main(String[] args)
Scanner keyboard = new Scanner(System.in);
int totaldoubles;
double total, nextnum, max, min;
String answer;
do
System.out.println();
System.out.println("Enter a list of nonnegative integers");
System.out.println("When you are finished with the list, enter a negative number");
System.out.println();
System.out.println("I will tell you the largest and smallest integer");
System.out.println("and give you the average the list");
totaldoubles = 0 ;
total = 0;
nextnum = keyboard.nextDouble();
max = nextnum;
min = nextnum;
while (nextnum >= 0)
total = total + nextnum;
totaldoubles++;
nextnum = keyboard.nextDouble();
if (nextnum > max)
max = nextnum;
else if (nextnum < min)
min = nextnum;
if (totaldoubles > 0)
System.out.println("The average is: " + (total/totaldoubles));
System.out.println("The largest number was: " + max);
else
System.out.println("No scores to average");
System.out.println();
System.out.println("Do you want to average another list?");
System.out.println("Enter Yes or No");
answer = keyboard.next();
}while (answer.equalsIgnoreCase("yes"));
But now the compiler is saying that the underlined "else" is without an if
Message was edited by:
thecynicle1
Message was edited by:
thecynicle1
Message was edited by:
thecynicle1 -
Relationship between "Account Group" and "GL Acct. number".
I need to create a report that lists the GL Account numbers according to selection screen parameter "Account Group" .
Hi i need to find a way\(tables and fields) between the "Account Group" and
the "GL Account number".
to view "Account Group" go to transaction "kdh3".
to view GL account number go to transaction FS00.
the GL account numbers and cost centers are identified by the same number.Hi guys, thanks for helping
Max, i tried that field, but it provides a different set of data compared to the account groups i get using the "F4" on KDH3
Chandrasekhar, i had a look at the view, but it also does not contain the same account groups as found in KDH3.
I have been stuck on this for a while.
thanks again -
Query for getting records max reported timestamp and 2nd max report
query for getting records in between
max reported timestamp and 2nd max reported timestamp
HERE IS ALL RESULT SET
TIME DOMAIN
30:jun:2006:20:08:45 TOMCAT
30:jun:2006:20:08:45 TOMCAT
30:jun:2006:20:07:04 TOMCAT
30:jun:2006:20:07:04 TOMCAT
30:jun:2006:20:07:24 TOMCAT
30:jun:2006:20:07:24 TOMCAT
30:jun:2006:20:07:45 TOMCAT
30:jun:2006:20:07:45 TOMCAT
30:jun:2006:20:08:05 TOMCAT
30:jun:2006:20:07:04 TOMCAT
30:jun:2006:20:08:05 TOMCAT
PD_REPORTED_TIMESTAM PD_USER
30:jun:2006:20:08:25 TOMCAT
30:jun:2006:20:08:25 TOMCAT
30:jun:2006:20:08:45 TOMCAT
30:jun:2006:20:08:45 TOMCAT
30:jun:2006:20:07:24 TOMCAT
30:jun:2006:20:07:04 TOMCAT
30:jun:2006:20:07:24 TOMCAT
30:jun:2006:20:07:45 TOMCAT
30:jun:2006:20:07:45 TOMCAT
30:jun:2006:20:08:05 TOMCAT
30:jun:2006:20:08:05 TOMCAT
PD_REPORTED_TIMESTAM PD_USER
30:jun:2006:20:08:25 TOMCAT
30:jun:2006:20:08:25 TOMCAT
QUERY RESULT TO COME
TIME DOMAIN
TOMCAT 30:jun:2006:20:08:45
TOMCAT 30:jun:2006:20:08:45
TOMCAT 30:jun:2006:20:08:45
TOMCAT 30:jun:2006:20:08:45
Message was edited by:
user517983Hi,
can we write query like this.
1 select pd_user,PD_REPORTED_TIMESTAMP
2 from sp_process_detail_current spdc
3 where host_id='DSCP02469'and pd_user='TOMCAT'
4 and exists(
5 select PD_REPORTED_TIMESTAMP from sp_process_detail_current
6* having max(PD_REPORTED_TIMESTAMP)-spdc.PD_REPORTED_TIMESTAMP=0)
SQL> /
PD_USER PD_REPORTED_TIMESTAM
TOMCAT 30:jun:2006:20:08:45
TOMCAT 30:jun:2006:20:08:45
TOMCAT 30:jun:2006:20:08:45
TOMCAT 30:jun:2006:20:08:45 -
Numbering Group G1 can be used only for one CoCd and cash journal number
Hello,
I was trying to create a cash journal when I got the error message:
"Numbering Group G1 can be used only for one CoCd and cash journal number".
Does anyone have an idea what could be wrong?
Thank you,
BolaHi,
Please check whether more than one number range is maintained in transaction code FBCJC1. If yes, please keep only one as Cash Journal has only one number range. This is the internal number range for Cash Journal.
If you want different number range for accounting documents then create new document types and assign number ranges to it.
Regards,
Tejas -
How to work even and odd number query
Plz explain how below worked even and odd query
2 ) why used subquery after from and which time we can use(what time of out put)
even
select * FROM (SELECT ROW_NUMBER() OVER(ORDER BY stud_id) as row ,grno,stud_id from stud_Enrollment) d
WHERE d.row %2=0
odd
select * FROM (SELECT ROW_NUMBER() OVER(ORDER BY stud_id) as row ,grno,stud_id from stud_Enrollment) d
WHERE d.row %2=1Row_Number function returns the sequential number of a row
(By using partition of a result set, starting at 1 for the first row in each partition)
>> why used subquery after from and which time we can use(what time of out put)
When we need sequntial numbers, we can use row_number function. Put it into derived table and use this derived table after FROM clause (Same way it is used in your query)
CREATE TABLE stud_Enrollment (
grno int,
stud_id int,
stud_name varchar(20)
INSERT INTO stud_Enrollment
VALUES (101, 511, 'Dheeraj'), (112, 521, 'Vaibhav'), (132, 522, 'Lalit'), (124, 564, 'Amogh'), (143, 598, 'Sushrut')
SELECT * FROM stud_Enrollment
-- Result of your table
--grno stud_id stud_name
--101 511 Dheeraj
--112 521 Vaibhav
--132 522 Lalit
--124 564 Amogh
--143 598 Sushrut
-- Now we need to find out the rows which are at even position, ie row should be at position of 0,2,4,6,8 etc..
-- But we don't have sequential number here in your table result
-- So we can create one new column by using row_number function
SELECT
ROW_NUMBER() OVER (ORDER BY stud_id) AS row, --> additiona "row" column
grno,
stud_id,
stud_name
FROM stud_Enrollment
-- We got "row" column in below output
--row grno stud_id stud_name
--1 101 511 Dheeraj
--2 112 521 Vaibhav
--3 132 522 Lalit
--4 124 564 Amogh
--5 143 598 Sushrut
-- Now above table is used after FROM clause. It uses row column in WHERE part
SELECT
FROM (SELECT
ROW_NUMBER() OVER (ORDER BY stud_id) AS row,
grno,
stud_id,
stud_name
FROM stud_Enrollment) d
WHERE d.row % 2 = 0
--row grno stud_id stud_name
--2 112 521 Vaibhav
--4 124 564 Amogh
-Vaibhav Chaudhari -
What is the Largest and Fastest Hard drive that can be installed in my 17" Mac Book Pro i7 duo core 2.8 I need it to be compatible with Final Cut Pro 7
One of these SSDs:
http://eshop.macsales.com/item/OWC/SSDMX6G480/
An SSD is always a faster storage solution. A regular hard drive will almost ALWAYS be the bottleneck in a system, because it's the only part in a computer that has physical, moving parts. The SSD has no moving parts, so there's much less latency when reading and writing. That particular SSD is designed with professionals in mind, meaning that it will right at home rendering video in Final Cut. Hope that helps! -
Hello every one.
I have following data
Table 1:
ID LOC ST
1 30 12 gate
2 25 65 Jfk
3 45 45 Water
4 65 888 st
5 105 west st
5 110 north pole
6 999 wash. st
6 888 ind. ave
Table 2:
ID CT LOC ST
1 12 50 1 main
1 11 40 123 main
1 11 30 12 gate
1 12 30 12 gate
2 15 10 3 main
2 17 25 65 jfk
2 15 25 65 Jfk
3 25 45 45 Water
3 25 90 55 east st
3 100 90 55 east st
4 125 65 888 st
5 222 105 west st
5 333 110 north pole
6 55 999 wash. st
6 55 888 ind. ave
Expected result:
ID LOC ST OTHERSTCT OnlySt
1 30 12 gate Y N
2 25 65 Jfk N N
3 45 45 Water Y N
4 65 888 st N Y
5 105 west st N N
5 110 north pole N N
6 999 wash. st N N
6 888 ind. ave N NI tried but the results are not correct, Also I am using same tables again and again.
WITH temp1 AS(
SELECT 1 ID,30 loc ,'12 gate' st FROM dual
UNION ALL
SELECT 2 ID,25 loc,'65 Jfk' st FROM dual
UNION ALL
SELECT 3 ID,45 loc,'45 Water' st FROM dual
UNION ALL
SELECT 4 ID,65 loc,'888 st' st FROM dual
UNION ALL
SELECT 5 ID,105 loc,'west st' st FROM dual
UNION ALL
SELECT 5 ID,110 loc,'north pole' st FROM dual
UNION ALL
SELECT 6 ID,999 loc,'wash. st' st FROM dual
UNION ALL
SELECT 6 ID,888 loc,'ind. ave' st FROM dual
temp2 AS (SELECT 1 ID,12 ct,50 loc,'1 main' st FROM dual
UNION ALL
SELECT 1 ID,11 ct,40 loc,'123 main' st FROM dual
UNION ALL
SELECT 1 ID,11 ct,30 loc,'12 gate' st FROM dual
UNION ALL
SELECT 1 ID,12 ct,30 loc ,'12 gate' st FROM dual
UNION ALL
SELECT 2 ID,15 ct,10 loc,'3 main' st FROM dual
UNION ALL
SELECT 2 ID,17 ct,25 loc,'65 jfk' st FROM dual
UNION ALL
SELECT 2 ID,15 ct,25 loc,'65 Jfk' st FROM dual
UNION ALL
SELECT 3 ID,25 ct,45 loc,'45 Water' st FROM dual
UNION ALL
SELECT 3 ID,25 ct,90 loc,'55 east st' st FROM dual
UNION ALL
SELECT 3 ID,100 ct,90 loc,'55 east st' st FROM dual
UNION ALL
SELECT 4 ID,125 ct,65 loc,'888 st' st FROM dual
UNION ALL
SELECT 5 ID,222 ct,105 loc,'west st' st FROM dual
UNION ALL
SELECT 5 ID,333 ct,110 loc,'north pole' st FROM dual
UNION ALL
SELECT 6 ID,55 ct,999 loc,'wash. st' st FROM dual
UNION ALL
SELECT 6 ID,55 ct,888 loc,'ind. ave' st FROM dual
SELECT temp1.*,
(CASE
WHEN temp1.ID = d.ID THEN 'N'
ELSE 'Y'
END) otherCtSt
FROM temp1,
(SELECT t2.ID,
t2.ct
FROM temp1 t1,
temp2 t2
WHERE T1.ID = t2.ID
AND t1.loc = t2.loc
MINUS
SELECT t2.ID,
t2.ct
FROM temp1 t1,
temp2 t2
WHERE T1.ID = t2.ID
AND t1.loc != t2.loc) d
WHERE temp1.ID = d.ID(+)
ID LOC ST OTHERCTST
1 30 12 gate Y
2 25 65 Jfk N
3 45 45 Water Y
4 65 888 st N
5 105 west st Y <<<<- this is wrong
5 110 north pole Y <<<<- this is wrong
6 999 wash. st Y <<<<- this is wrong
6 888 ind. ave Y <<<<- this is wrongFlag: OtherCtSt Y and N
Flag:Onlyst means only distinct id and loc in table 2
Let me explain what I am looking for.
1. If the address in the table 1 is the only address in table 2 then OTHERSTCT =’N’ and OnlySt=’N’ example is id=4 and loc=65
2. Id and loc in table one has ct in table 2, If all ct in table 2 for that id and loc exists for same id and other loc in table 2 then flags Y and N. Example id=1
loc=30(table 1) and id=1 and loc(50,40) has same ct in table 2. Id=1,loc=30 in table 1 has ct 11,12, same ct 11,12 exists for id1 and loc(40,50) so the
flags shuld get Y and N (multiple id and loc in table 2)
3. falgs Y and N same as above example falls for id 3 and loc 45 in table 1 as id 3 and loc 45 has ct 25 in table 2 and same ct 25 also exists for id3 and other
loc 90
4. Id 2 gets flag N and N because id 2 and loc 25 has two ct (15,17) while id 2 has only one other ct 15 for loc 10 and no other loc or same loc has ct 17
so flag one gets N and flag2 gets N as multiple id and loc in table 2
5. Id 5 loc 105 and 110 should get N and N as id 5 and loc 105 has ct=222 there is no other loc which has same ct 222 and same applies for id=5 and loc
=110 as it has ct=333 and no other id and loc has ct=333. also Same no of record are in table 1 and table 2. Same id and same loc in table 1 and table
2 so both should get N N
6. id 6 , loc 999,888 should get N and N as Id 6 and loc 999 has ct 55 in table 2 ,but same ct 55 also exists for id 6 and loc 888 so should get N and N .
same for id 6 and loc 888, Same no of record are in table 1 and table 2. Same id and same loc in table 1 and table 2 so both should get N N
I hope I have explained it correctly. Please let me know if it is confusing.
Thank you in advance for your help.Thank you for the response, I added some more scenarios to explain more in detail.
Let me explain. id and loc in table 1 has corresponding id,ct and loc in the table 2.
Now each combination of ID and LOC has CT associated with it in table 2, I want to find from table 1 that table 2 should have same ID and CT with different LOC in table 2.
1. for id 1 and loc 3 in table 1 has CT=11 and 12. Table 2 has same CT 12,14 for LOC 40 and 50 so that ID 1 and LOC 30. Flag in table 1 flag='Y'
2. For id 2 and loc 25 in table 1 has CT=15 and 17, Table 2 has only CT 15 for LOC 10 and there is no other LOC with CT 17( it could loc 10 also)
Flag in table 1 for ID2 and loc 25 N
3. Id 3 and loc 45 in table 1 has CT=25, table 2 has ct=25 with id=3 and loc 90( id=3 ,loc90 and ct=100 is immaterial) so table 1 Flag=Y
4. Id 4 and loc 65 ct =125, Table 2 has no same ID and other LOC which has CT=125 so FLAG='N'
5. Id 5 and LOC 105 ct=222 in table 1, Table 2 has no same ID and other LOC which has CT=222 So FLAG='N' and same is for ID 5 and LOC 110. Also there are
only two row in table 2 which are same in table 2 and there is no other LOC for same address so by default it should get Flag N. Means if no of distinct
Records in both tables are same then also the flag should get N
6. ID 6 and LOC 999 and 888 in table 1 has CT=55 in table 1 for both, Table 2 CT=55 for each other, it should qualify for flag=Y but distinct count
of ID and LOC in both table are same so flag =N
7. ID 7 and LOC 101 in table has CT=33, table 2 has id=7 and other loc=170 which has ct=33 so it should qualify for Y but at a same time
ID 7 and LOC 170 also has CT =33 and present id table so they wipe out each other, so it doesn’t qualify for Y so flag should be 'N'
8. ID 8 and loc 662 in table 1 has CT=22, in table 2 there is no same ID and other loc has CT=22 so flag= N
9. Finally the iD 9 and loc 7 in table has ct=22, in table 2 id=9 and loc 4 has ct=22 for ID=9 and LOC=7 flag=Y
While ID=9 and loc=6 in table has ct=17, but in table 2 there is no other loc has ct=17 for ID 9 so ID=9 and LOC=6 flag='N'.
There is one more flag if there is only one ID and LOC in table 1 and table 2t then FLAG 2 should be Y other wise N. in this test case only ID 4 and loc 65 gets Y and all gets N.
If need more info please let me know.
Table 1
ID LOC ST
1 30 12 gate
2 25 65 Jfk
3 45 45 Water
4 65 888 st
5 105 west st
5 110 north pole
6 888 ind. ave
6 999 wash. st
7 101 666 sardar
7 170 gandhi st
8 662 Sv raod
9 6 MG road
9 7 Sv raodTable 2
ID CT LOC ST
1 11 30 12 gate
1 12 30 12 gate
1 11 40 123 main
1 12 50 1 main
2 15 10 3 main
2 15 25 65 Jfk
2 17 25 65 jfk
3 25 45 45 Water
3 25 90 55 east st
3 100 90 55 east st
4 125 65 888 st
5 222 105 west st
5 333 110 north pole
6 55 888 ind. ave
6 55 999 wash. st
7 44 100 55 gmail
7 33 101 666 sardar
7 33 170 gandhi st
7 44 170 gandhi st
8 15 564 Om st
8 22 662 Sv raod
8 17 665 Shiva st
9 22 4 sky ln
9 17 6 MG road
9 22 7 Sv raodResult Expected from table 1
ID LOC ST FLAG FLAG2
1 30 12 gate Y N
2 25 65 Jfk N N
3 45 45 Water Y N
4 65 888 st N Y
5 105 west st N N
5 110 north pole N N
6 999 wash. st N N
6 888 ind. ave N N
7 170 gandhi st N N
7 101 666 sardar N N
8 662 Sv raod N N
9 6 MG road N N
9 7 Sv raod Y NHere the sample data query.
WITH temp1 AS(
SELECT 1 ID,30 loc ,'12 gate' st FROM dual
UNION ALL
SELECT 2 ID,25 loc,'65 Jfk' st FROM dual
UNION ALL
SELECT 3 ID,45 loc,'45 Water' st FROM dual
UNION ALL
SELECT 4 ID,65 loc,'888 st' st FROM dual
UNION ALL
SELECT 5 ID,105 loc,'west st' st FROM dual
UNION ALL
SELECT 5 ID,110 loc,'north pole' st FROM dual
UNION ALL
SELECT 6 ID,999 loc,'wash. st' st FROM dual
UNION ALL
SELECT 6 ID,888 loc,'ind. ave' st FROM dual
UNION ALL
SELECT 7 ID,170 loc,'gandhi st' st FROM dual
UNION ALL
SELECT 7 ID,101 loc,'666 sardar' st FROM dual
UNION ALL
SELECT 8 ID,662 loc ,'Sv raod' st FROM dual
UNION ALL
SELECT 9 ID,6 loc ,'MG road' st FROM dual
UNION ALL
SELECT 9 ID,7 loc ,'Sv raod' st FROM dual
temp2 AS (
SELECT 1 ID,12 ct,50 loc,'1 main' st FROM dual
UNION ALL
SELECT 1 ID,11 ct,40 loc,'123 main' st FROM dual
UNION ALL
SELECT 1 ID,11 ct,30 loc,'12 gate' st FROM dual
UNION ALL
SELECT 1 ID,12 ct,30 loc ,'12 gate' st FROM dual
UNION ALL
SELECT 2 ID,15 ct,10 loc,'3 main' st FROM dual
UNION ALL
SELECT 2 ID,17 ct,25 loc,'65 jfk' st FROM dual
UNION ALL
SELECT 2 ID,15 ct,25 loc,'65 Jfk' st FROM dual
UNION ALL
SELECT 3 ID,25 ct,45 loc,'45 Water' st FROM dual
UNION ALL
SELECT 3 ID,25 ct,90 loc,'55 east st' st FROM dual
UNION ALL
SELECT 3 ID,100 ct,90 loc,'55 east st' st FROM dual
UNION ALL
SELECT 4 ID,125 ct,65 loc,'888 st' st FROM dual
UNION ALL
SELECT 5 ID,222 ct,105 loc,'west st' st FROM dual
UNION ALL
SELECT 5 ID,333 ct,110 loc,'north pole' st FROM dual
UNION ALL
SELECT 6 ID,55 ct,999 loc,'wash. st' st FROM dual
UNION ALL
SELECT 6 ID,55 ct,888 loc,'ind. ave' st FROM dual
UNION ALL
SELECT 7 ID,44 ct,100 loc,'55 gmail' st FROM dual
UNION ALL
SELECT 7 ID,33 ct,101 loc,'666 sardar' st FROM dual
UNION ALL
SELECT 7 ID,44 ct,170 loc,'gandhi st' st FROM dual
UNION ALL
SELECT 7 ID,33 ct,170 loc ,'gandhi st' st FROM dual
UNION ALL
SELECT 8 ID,15 ct,564 loc ,'Om st' st FROM dual
UNION ALL
SELECT 8 ID,17 ct,665 loc ,'Shiva st' st FROM dual
UNION ALL
SELECT 8 ID,22 ct,662 loc ,'Sv raod' st FROM dual
UNION ALL
SELECT 9 ID,22 ct,4 loc ,'sky ln' st FROM dual
UNION ALL
SELECT 9 ID,17 ct,6 loc ,'MG road' st FROM dual
UNION ALL
SELECT 9 ID,22 ct,7 loc ,'Sv raod' st FROM dual
SELECT temp1.*,
d.flag
FROM (SELECT d1.ID,
id1ct1,
id3ct3,
id1ct1loc1,
id3ct3loc3,
id1loc1,
id3loc3,
(CASE
WHEN ( (id1ct1 = id3ct3
AND id1ct1loc1 = id3ct3loc3
AND id1loc1 = id3loc3)
OR (id1ct1 <> id3ct3
AND id1ct1loc1 <> id3ct3loc3
AND id1loc1 <> id3loc3) ) THEN 'N'
ELSE (CASE
WHEN (id1ct1 <= id3ct3
AND id1ct1loc1 <= id3ct3loc3
AND id1loc1 <= id3loc3) THEN 'Y'
ELSE 'N'
END)
END) flag
FROM (SELECT t2.ID,
COUNT (DISTINCT t2.ID || t2.ct) id1ct1,
COUNT (DISTINCT t2.ID || t2.ct || t2.loc) id1ct1loc1,
COUNT (DISTINCT t2.ID || t2.LOC) id1loc1
FROM temp1 t1,
temp2 t2
WHERE T1.ID = t2.ID
AND t1.loc = t2.loc
GROUP BY t2.ID) d1
FULL OUTER JOIN
(SELECT DISTINCT t2.ID,
COUNT (DISTINCT t2.ID || t2.ct) id3ct3,
COUNT (DISTINCT t2.ID || t2.ct || t2.loc) id3ct3loc3,
COUNT (DISTINCT t2.ID || t2.LOC) id3loc3
FROM temp1 t1,
temp2 t2
WHERE T1.ID = t2.ID
AND t1.loc != t2.loc
GROUP BY t2.ID) d3 ON (d1.ID = d3.ID)
) d,
temp1
WHERE temp1.ID = d.IDI tried and got FOLLOWING results
ID LOC ST FLAG
1 30 12 gate Y
2 25 65 Jfk N
3 45 45 Water Y
4 65 888 st N
5 105 west st N
5 110 north pole N
6 999 wash. st N
6 888 ind. ave N
7 170 gandhi st Y << this is wrong
7 101 666 sardar Y << this is wrong
8 662 Sv raod N
9 6 MG road Y << this is wrong
9 7 Sv raod Y Once again thank you and please let me nkow if i missed something. -
Sharepont Designer saves AND/OR CAML Query groups incorrectly
My objective is to display active tasks on a certain date: Started on or before and Due on or after; Started on or before and not Completed. The date is provided via a webpart connection parameter.
I used CAML Designer 2013 and SP CAML Query 2013 to verify and then modified the Query string for the Tasks WebPart in Sharepoint Designer as follows:
<Query><Where>
<Or>
<And>
<Leq><FieldRef Name="StartDate"/><Value Type="DateTime">{ParmMeetingDate}</Value></Leq>
<Geq><FieldRef Name="DueDate"/><Value Type="DateTime">{ParmMeetingDate}</Value></Geq>
</And>
<And>
<Neq><FieldRef Name="Status"/><Value Type="Text">Completed</Value></Neq>
<Leq><FieldRef Name="StartDate"/><Value Type="DateTime">{ParmMeetingDate}</Value></Leq>
</And>
</Or>
</Where></Query>
However, when I save the page in SharePoint Designer, and edit the web page from the browser, the Filter criteria are:
Start date Less than or equal to {ParmMeetingDate}
AND DueDate Greater than or equal to
AND Task Status is not equal to Completed
OR Start Date is less than or equal to {ParmMeetingDate}
If I correct the settings in the browser and save, the Query String in SPD is changed to:
<Query><Where>
<Or><Or>
<And>
<Leq><FieldRef Name="StartDate"/><Value Type="DateTime">{ParmMeetingDate}</Value></Leq>
<Geq><FieldRef Name="DueDate"/><Value Type="DateTime">{ParmMeetingDate}</Value></Geq>
</And>
<Leq><FieldRef Name="StartDate"/><Value Type="DateTime">{ParmMeetingDate}</Value></Leq>
</Or>
<Neq><FieldRef Name="Status"/><Value Type="Text">Completed</Value></Neq>
</Or></Where></Query>
How can I get SPD/SP to save the CAML query correctly?Update: Another effect of the problem outlined above was that no results were displayed for any parameterised filter values - regardless of the query.
I came across a reference to the Server Render webpart attribute. When this attribute is selected on the webpart a number of things happen:
The Timeline at the top of the Tasks list view webpart is switched off
The completed icon changes to a Yes/No value
The filters work!!!
Saving the filters works!!!
The List View Tools tab appears in SharePoint Designer!!!
I have no idea what the Server Render attribute is and/or why it is set off by default. I don't why it affects the appearance of the List View Tools tab in the ribbon - I can't think of any reason why it should. And I don't know why it affects
the filter query or why it should...
At a high level I presume the Server Render attribute tells sharepoint to process on the server rather than on the client. It may make sense to pas the processing from the server to the client. It makes no sense that this would restrict functionality
(disable List View Tolls in SPD) or produce different results (no results in Filtered webpart).
Do you know if this issue has been identified as a bug; has it been resolved? -
Finding largest and smallest using inputStream
I'm having trouble coming up with the logic to find the largest and smallest scores of an input stream. Am I on the write track, hints?
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class Exercise10
public static void main(String[] args)
//declare the filenames
String fileIn = "in.txt";
String fileOut = "out.txt";
//use Scanner for input
Scanner streamIn = null;
//use PrintWriter for output
PrintWriter streamOut = null;
int count = 0;
double sum = 0;
double n;
double large = 0;
try
streamIn = new Scanner(new File(fileIn));
streamOut = new PrintWriter(fileOut);
catch(FileNotFoundException e)
System.out.println("Error opening the file "+fileIn+" or "+fileOut+".\n");
System.exit(0);
System.out.println("Scores have been outputted to " +fileOut+ ".\n");
//loop if there is another line in fileIn
while(streamIn.hasNextInt())
n = streamIn.nextInt();
double previous = n;
if(previous>n)
large = previous;
else
large = n;
//find the largest score in the file
if(n>= 0 && n<=100)
count++;
sum = sum + n;
else
streamOut.println("Your score is out of range.");
//close the stream in
streamIn.close();
//write the information
streamOut.println("There are " +count+" grades in the "+fileIn+ " file.");
streamOut.println("The total sum of the grades is: "+sum);
streamOut.println("The average is: "+sum / count);
streamOut.println("The largest score is: "+large);
//close the stream out, will not write unless closed.
streamOut.close();
}Edited by: brandonacoughlin on Nov 12, 2009 8:25 PMif(n>= 0 && n<=100)
//find the largest score in the file
if(n>=large)
large = n;
//find the smallest score in the file
else if(n<=small)
small = n;
} -
Query Group in Query Category different with Authorization's group number
Hi All,
In Authorization screen, it allowed to authorize up to 20 query group
Whereas in Query Category window, it has only max 15 query group.
Anyone has idea on why is the difference?
Thanks in advance,
MHYou have a very good point. I believe something must be for system to use during development. You may post a development request to see if the next version could have matched numbers of query groups. The forum is on this link:
/community [original link is broken]
Thanks,
Gordon
Edited by: Paulo Calado on Jun 19, 2009 3:33 PM
Maybe you are looking for
-
In my iphone 5s music palyer is not opening its just blink and comes to the home screen.
in my iphone 5s music palyer is not opening its just blink and comes to the home screen.
-
Can't Sign in Using Regular AppleID
When I try to sign in with my regular appleID, I get the message "We're sorry, your account could not be created due to a system issue." I don't want to make my regular AppleID public, because it's my personal email address, and the email address ass
-
MOVED: Adding a Flat Screen Monitor as a 2nd Monitor to an Integrated Motherboard/Video
This topic has been moved to AMD64 boards. https://forum-en.msi.com/index.php?topic=162308.0
-
Ora 12154 error when trying to add a database to VS Server Explorer
Hi Everyone, I get the Ora 12154 error when trying to add a database to VS Server Explorer. How do I get around this problem. The database service is running and I can connect to the database with pl/sql. I can also tnsping the database and that is a
-
Experts, We are trying to install the .net connector server for AD 11.1.1.5.0 connector server using 32 bit Windows 2003 server. But after this step: From the installation media, copy and extract contents of the bundle/ActiveDirectory.Connector-1.1.0