How to make this query efficient
create table temp)au_sa_poi_geocoding2 as select idx, address_form, suburb_form
from temp_au_Sa_poi_geocoding a where idx not in (select idx from gc1_Sa_sub where status='m' ) and exists (select null from sh_poi_small cites c
where upper (trim(a.suburb_form))=c.city)
one table contain round 74214 records while the other has less than that.
the tables were not indexed, i created index using the following commands.
create index sa_idx on temp_au_sa_poi_geocoding(idx)
create index sa1_idx on gc1_sa_sub(idx)
anyhelp would be appreciated.
thanks
create index sa0_idx on temp_au_Sa_poi_geocoding(upper(trim(suburb_form)));
create index sa1_idx on gc1_sa_sub(status,idx); -- instead of only (idx)
create index sh_idx on sh_poi_small (city);
then try as follows
create table temp_au_sa_poi_geocoding2 as select idx,
address_form, suburb_form
from temp_au_Sa_poi_geocoding a where idx not in
(select /*+ index gc1 */ idx from gc1_Sa_sub gc1 where status='m' ) and
exists (select /*+ index_join c a */ null from sh_poi_small cites c
where upper (trim(a.suburb_form))=c.city)
however effects of indexes will vary by cardinality.
Similar Messages
-
How do make this query ?
CREATE TABLE CLIENT (
CLIENTID NUMBER PRIMARY KEY,
NAME VARCHAR2(40)
CREATE TABLE SALESMAN (
SALESMANID NUMBER PRIMARY KEY,
NAME VARCHAR2(40),
ALL_CLIENTS NUMBER -- ACCESS ALL CLIENTS IF VALUE IS 1
CREATE TABLE CLIENTSALESMAN (
SALESMANID NUMBER,
CLIENTID NUMBER
INSERT INTO CLIENT VALUES(1,'Bob');
INSERT INTO CLIENT VALUES(2,'Jhon');
INSERT INTO CLIENT VALUES(3,'Robert');
INSERT INTO CLIENT VALUES(4,'Clarck');
INSERT INTO SALESMAN VALUES (1,'Christina',0);
INSERT INTO SALESMAN VALUES (2,'Doug',1); -- access all clients
INSERT INTO CLIENTSALESMAN VALUES (1,1);
INSERT INTO CLIENTSALESMAN VALUES (1,2);
How do you return all the clients of a salesman ? same that SALESMAN.ALL = 1 OR SALESMAN.ALL = 0.
the salesman.all is 1 then he access all clients no need insert in CLIENTSALESMAN. If SALESMAN.ALL = 0 he
access clientsalesman.
Does somebody some suggestion how i make this ?
thanks !1 select *
2 from (select a.name SALESMAN, b.name CLIENT
3 from salesman a, client b, clientsalesman
4 where a.SALESMANID = c.SALESMANID
5 and b.CLIENTID = c.CLIENTID
6 union
7 select a.name SALESMAN, b.name CLIENT
8 from salesman a, client b
9 where a.ALL_CLIENTS = 1)
10* where salesman = '&1'
SQL> /
Enter value for 1: Christina
old 10: where salesman = '&1'
new 10: where salesman = 'Christina'
Christina Bob
Christina Jhon
SQL> /
Enter value for 1: Doug
old 10: where salesman = '&1'
new 10: where salesman = 'Doug'
Doug Bob
Doug Clarck
Doug Jhon
Doug RobertNicolas. -
How to make this query more efficient
Hi, i have query to find out the count of records based on certain conditions like below.
SELECT count(*)
FROM new_orders WHERE card_number IS NOT NULL
AND exp_date IS NOT NULL
AND card_id in ( select card_id from old_orders );
There are millions of records in both the tables. , so it is taking long time to run. Is there any solution to optimize this query.....thanks for help. Bcjyou might want to give this a try.
SELECT count(*)
FROM new_orders no
WHERE no.card_number IS NOT NULL
AND no.exp_date IS NOT NULL
AND exists (select 'x'
from old_orders oo
where oo.card_id = no.card_id);it would also help if you can post the information needed as suggested by rob. -
Please Suggest, How to make this view efficient ?
Hi there,
Could you please suggest me,how to make the following VIEW (QUERY) efficient regarding performance point of view.
CREATE OR REPLACE VIEW XXX_TRX_TO_NUM_V
(ROW_NUM, ORIG_TRX_NUM, TRX_NUMBER, TRX_DATE, PURCHASE_ORDER,INTERFACE_HEADER_ATTRIBUTE6, INTERFACE_HEADER_ATTRIBUTE1, INTERFACE_HEADER_ATTRIBUTE5, BILL_TO_CONTACT_ID, REMIT_TO_ADDRESS_ID, BILL_TO_CUSTOMER_ID, BILL_TO_SITE_USE_ID, ORG_ID)
AS
Select rownum row_num,trx_number orig_trx_num,to_number(a.trx_number) trx_number,a.trx_date,a.purchase_order,a.interface_header_attribute1
,a.interface_header_attribute6,a.interface_header_attribute5,a.bill_to_contact_id
,a.remit_to_address_id,a.bill_to_customer_id,a.bill_to_site_use_id,a.org_id
from ra_customer_trx_all a
where a.trx_number is not null
and a.trx_number not in
(select trx_number
from
(select rownum,/*+ ALL_ROWS ,16 */ r.trx_number,ltrim(rtrim(translate(/*+ ALL_ROWS ,16 */ r.TRX_number,'0123456789',' '), ' ' ), ' ' ) tx
from ra_customer_trx_all r)
where tx is not null)
order by trx_number
Thanks in Advance !
ShahzadI think you have the hints in the wrong place - as far as I was aware, the hint had to come straight after the SELECT/UPDATE/INSERT/DELETE key word - but I could be wrong as I've never really tried it elsewhere. Also, unless the optimiser mode for your database is set to FIRST_ROWS or RULE (god help you!:), ALL_ROWS is the default behaviour.
Basically what you are trying to say is bring me back all ra_customer_trx_all rows that have purely numeric trx_numbers right?
Why, if you need to be able to represent trx_number as a number, do you have non-numeric data in there???? That's a bit dodgy isn't it?
Anyway, what about:
CREATE TABLE dt_test_num (id varchar2(10))
insert
into
dt_test_num
select
chr(47 + rownum)
from
all_tables
where
rownum <= 20
select
to_number(id),
id
from
dt_test_num
where
translate(id,'0123456789',' ') IS NULL
update
dt_test_num
set
id=id||chr(67-rownum)
select
FROM
dt_test_num
select
to_number(id),
id
from
dt_test_num
where
translate(id,'0123456789',' ') IS NULL
/Also, you are selecting rownum and aliasing it. Why? rownum will be assigned before the sort.
HTH
David
Message was edited by:
david_tyler
Hello
Slight correction to the where clause. Art first I thought you didn't need the trim on there, but that was just down to the number sequence in translate...
SQL> select nvl(translate('1A','1234567890',''),'NULL') from dual
2 /
NVL(
NULL
SQL> select nvl(translate('1A','1234567890',' '),'NULL') from dual
2 /
NV
A
SQL> select nvl(translate('1','1234567890',' '),'NULL') from dual
2 /
N
SQL> select nvl(translate('2','1234567890',' '),'NULL') from dual
2 /
NVL(
NULL
SQL> select nvl(translate('2','0123456789',' '),'NULL') from dual
2 /
NVL(
NULL
SQL> select nvl(translate('1','0123456789',' '),'NULL') from dual
2 /
NVL(
NULL
SQL> select nvl(translate('0','0123456789',' '),'NULL') from dual
2 /
N
SQL> select nvl(TRIM(translate('0','0123456789',' ')),'NULL') from dual
2 /
NVL(
NULL
SQL> select nvl(TRIM(translate('1','0123456789',' ')),'NULL') from dual
2 /
NVL(
NULLTranslate still confuses me :-( -
How to make this query go faster
Hi ,
I have the following query :
select a.* from
tbl1 a , tbl2 b
where a.id = b.id
substr(b.id , 3, 2) <> 'XX'
and b.date1 is not null
and b.date1 >= sysdate - 90 ;
tbl1 - 21 million rows
tbl2 - 2 millions
i specify this hints /*+ INDEX(idxa_1 , idxa_2) INDEX(ixdb_1)
where idxa_1 --> b.lotid
idxa_2 --> b.date1
idxb_1 --> a.lotid
IF i DO NOT include b.date1 is not null and b.date1 >= sysdate - 90 ,
from explain plan i could see it using a FAST FULL SCAN which really returns very fast
HOWEVER if i include b.date1 is not null and b.date1 >= sysdate - 90
, from explain plain it uses row index and then there's a range scan and its slow
how can i improve the performance of this query ?
pls advise
tks & rdgsDon't create the temporary table.
Create a function based index on table two
substr(id , 3, 2)Make sure you have gathered statistics on the tables.
Remove the hint.
select a.* from
tbl1 a , tbl2 b
where a.id = b.id
and substr(b.id , 3, 2) <> 'XX'
and b.date1 >= sysdate - 90;If you still have performance problems, post the formatted explain plan from sqlplus.
Read the Performance Tuning Guide.
Unfortunately this is not urs advice. -
hi,
i have 2 tables emp1 & emp2
emp1 consist
empno month amt
001 201002 200
001 201003 100
emp2 consist
empno month amt
001 201001 100
001 201002 200
001 201003 100
i want to make a query on emp1 table where i want to show amt according to month ,if data is not available in emp1 table then only then it should take data from emp2 table ,if emp2 has that month data o/w 0.
my output should be like this
empno month amt
001 201001 100
001 201002 200
001 201003 100
regardsMay be....
SQL> WITH emp1 AS (SELECT '001' empno,'201002' mon,200 amt FROM DUAL UNION ALL
2 SELECT '001' empno,'201003' mon,100 amt FROM DUAL
3 )
4 ,emp2 AS ( SELECT '001' empno,'201001' mon,100 amt FROM DUAL UNION ALL
5 SELECT '001' empno,'201002' mon,200 amt FROM DUAL UNION ALL
6 SELECT '001' empno,'201003' mon,100 amt FROM DUAL
7 )
8 SELECT coalesce(e1.empno,e2.empno) empno,
9 coalesce(e1.mon,e2.mon) mon,
10 coalesce(e1.amt,e2.amt)amt
11 FROM emp1 e1 FULL OUTER JOIN emp2 e2
12 ON e1.empno =e2.empno
13 AND e1.mon=e2.mon
14 ORDER BY 2 ;
EMP MON AMT
001 201001 100
001 201002 200
001 201003 100 -
How to make this program efficient?
Hola Amigos, I'm trying to explore all the possibilities about comparing two arrays. I know the following code is O(n^2) is it possible to make it O(n) without recursion or is recursion the only way. I ask this because we are being taught recursion and I don't quite understand it. I don't see the relation from recursion taught in Discrete Math with the one taught in programming, Thanks.....
public class twoArrays
public static int max = -1;
public static int findMax(int oneArray [], int twoArray [])
for (int i = 0 ; i < oneArray.length ; i ++)
for ( int j = 0; j < twoArray.length ; j++)
max = Math.max(max,Math.max(oneArray,twoArray[j]));
return max;
public static void main (String [] args)
int[] a = {1,5,8,30,80,99,140,160,170,180,190,200};
int[] b = {2,4,7,45,60,85,98,150,155,175,195,205};
findMax(a,b);
System.out.println("The highest value is: " + max);
Ah, one more thing the word "static" how can I call a method from a non-static context. Very confussing for me, thanks again.To call a non-static method you can use an instance of the class.
Example:
public class twoArrays {
public static int max = -1;
public int findMax(int oneArray [], int twoArray []){//non-static
for (int i = 0 ; i < oneArray.length ; i ++){
for ( int j = 0; j < twoArray.length ; j++) max = Math.max(max,Math.max(oneArray,twoArray[j])); }
return max;
public static void main (String [] args) {
int[] a = {1,5,8,30,80,99,140,160,170,180,190,200};
int[] b = {2,4,7,45,60,85,98,150,155,175,195,205};
( new twoArrays() ).findMax(a,b);/*through an anonymous instance of the class, you can call findMax method */
System.out.println("The highest value is: " + max);
Hope it will help you.
p.d.: max is initialized -1 cause then into findmax, you asure that max will never again has value -1 (the two arrays contains numbers > -1 )so max at least will be higher than -1.
Sorry for my english.
Saludos -
WITH
MEMBER [FYDay].[DateHierarchy].[CurrentDay] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[PreviousDay] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .PREVMEMBER }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay1] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(1) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay2] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(2) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay3] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(3) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay4] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(4) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay5] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(5) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay6] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(6) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay7] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(7) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[PTD] AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FPERIOD],
[FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
), [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[WTD] AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FWEEK],
[FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
), [Measures].CURRENTMEMBER)
SELECT
[FYDay].[DateHierarchy].[WTD],
[FYDay].[DateHierarchy].[PTD],
[FYDay].[DateHierarchy].[PreviousDay],
[FYDay].[DateHierarchy].[CurrentDay],
[FYDay].[DateHierarchy].[CurrentDay1],
[FYDay].[DateHierarchy].[CurrentDay2],
[FYDay].[DateHierarchy].[CurrentDay3],
[FYDay].[DateHierarchy].[CurrentDay4],
[FYDay].[DateHierarchy].[CurrentDay5],
[FYDay].[DateHierarchy].[CurrentDay6],
[FYDay].[DateHierarchy].[CurrentDay7]
} ON COLUMNS,
[Measures].[Store Budget],
[MEASURES].[SNAPSHOTSOLDAMOUNT],
[MEASURES].[SHIPPEDAMOUNT],
[MEASURES].[SHIPPED VS SOLD],
[Measures].[% To Budget]
{[STOREMASTER].[SERVICINGDC].[SERVICINGDC].ALLMEMBERS}
)} ON ROWS
from ( select {[STOREMASTER].[SERVICINGDC].&[Houston]} on columns
FROM [Model]Hi Ramparasad,
In your query, you add a measures and dimension on Row axis which is not supported in query designer in SSRS. Please use the query below.
WITH
MEMBER [FYDay].[DateHierarchy].[CurrentDay] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[PreviousDay] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .PREVMEMBER }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay1] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(1) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay2] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(2) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay3] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(3) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay4] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(4) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay5] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(5) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay6] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(6) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay7] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(7) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[PTD] AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FPERIOD],
[FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
), [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[WTD] AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FWEEK],
[FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
), [Measures].CURRENTMEMBER)
SELECT
[Measures].[Store Budget],
[MEASURES].[SNAPSHOTSOLDAMOUNT],
[MEASURES].[SHIPPEDAMOUNT],
[MEASURES].[SHIPPED VS SOLD],
[Measures].[% To Budget]
}ON COLUMNS,
{ [FYDay].[DateHierarchy].[WTD],
[FYDay].[DateHierarchy].[PTD],
[FYDay].[DateHierarchy].[PreviousDay],
[FYDay].[DateHierarchy].[CurrentDay],
[FYDay].[DateHierarchy].[CurrentDay1],
[FYDay].[DateHierarchy].[CurrentDay2],
[FYDay].[DateHierarchy].[CurrentDay3],
[FYDay].[DateHierarchy].[CurrentDay4],
[FYDay].[DateHierarchy].[CurrentDay5],
[FYDay].[DateHierarchy].[CurrentDay6],
[FYDay].[DateHierarchy].[CurrentDay7]
{[STOREMASTER].[SERVICINGDC].[SERVICINGDC].ALLMEMBERS}
} ON ROWS
from ( select {[STOREMASTER].[SERVICINGDC].&[Houston]} on columns
FROM [Model]
Regards,
Charlie Liao
TechNet Community Support -
hi,
i have a product table like
product month1 month2 month3 .................
soap 1200 1256 1895 ............
i want use a query where i can select column name with a parameter.
like
select month||:num from product;
in num variable it cud be 1 to 10 of value that is dependent on my program.
so how to make this query .
thxsHi,
Here is an example that i am helpful.
In the example , I am using a table 'table_name' which contains columns like
assign_attribute1
assign_attribute2
assign_attribute15
Now I will pass any number from 1 to 15 to the function.
create or replace procedure pass_col_number(v_number varchar2) as
v_sql varchar2(2000);
v_assign_attribute1 varchar2(150);
begin
v_sql := 'select assign_attribute'||v_number||' from table_name where person_id = 1345';
execute immediate v_sql into v_assign_attribute1;
dbms_output.put_line('v_assign_attribute1='||v_assign_attribute1);
end;Edited by: Sreekanth Munagala on Dec 18, 2008 1:18 AM -
How to write this query to filter combination of few values
Hi,
I have a table CHIMM which is a transaction table and contains information of the vaccines given to a child.
columns are: child_id, vacc_id, vacc_given_dt. I have to query for remaining vaccines.
HEXA is a vaccine_id which is composite vaccine of DPT1,POL1,HBV1 & HIB1 (vaccine ids).
I want to write to query if any of DPT1,POL1,HBV1 & HIB1 given then HEXA should not be displayed in the result.
OR
if HEXA is given then of course any of DPT1,POL1,HBV1 & HIB1 should not be displayed in the result.
How to write this query?
RegardsHi,
I'm still not sure what the output you want from that sample data is. Do you just want the child_ids, like this
CHILD_ID
3
4? If so, here's one way to get them:
WITH all_vacc_ids AS
SELECT c.child_id
, c.vacc_id AS child_vacc_id
, v.vacc_id
, COUNT ( CASE
WHEN c.vacc_id = 'HEXA'
THEN 1
END
) OVER ( PARTITION BY c.child_id
) AS hexa_itself
FROM vacc v
LEFT OUTER JOIN chimm c PARTITION BY (c.child_id)
ON c.vacc_id = v.vacc_id
WHERE v.vacc_desc = 'HEXA' -- See note below
SELECT child_id
FROM all_vacc_ids
WHERE child_vacc_id IS NULL
AND vacc_id != 'HEXA'
AND hexa_itself = 0
GROUP BY child_id
rha2 wrote:there are alot of vaccines, i just put 3 for example. this query gives error: invalid relational operatorAre you saying that the vacc table contains other rows, but those other rows are not needed for this problem? It would be good if you included an example in the sample data. The query above considers only the rows in vacc where vacc_desc='HEXA'. You can have other rows in the vacc table, but they won't affect the output of this query. The query above makes no assumptions about the number of rows that have vacc_desc='HEXA'; it will report all child_ids who are missing any of them, regardless of the number (assuming the child does not have the 'HEXA' vacc_id itself, like child_id=1).
You still haven't said which version of Oracle you're using. The query above will work in Oracle 10 (and higher). -
How to write this query ?
how to write this query ?
list the emp name who is working for the highest avg sal department.
I can use row_number over to get correct result. If we don't use this row_number function, just plain sql, how to do it ?
the row_number version is like this
select emp.* from emp ,
select deptno, row_number() over (order by avg(sal) desc) r from emp
group by deptno
)e
where e.r = 1
and emp.deptno = e.deptnoHi,
806540 wrote:
how to write this query ?
list the emp name who is working for the highest avg sal department.
I can use row_number over to get correct result. If we don't use this row_number function, just plain sql, how to do it ?ROW_NUMBER is just plain SQL, and has been since Oracle 8.1.
ROW_NUMBER (or its close relative, RANK) is the simplest and most efficient way to solve this problem. Why not do this the right way?
the row_number version is like this
select emp.* from emp ,
select deptno, row_number() over (order by avg(sal) desc) r from emp
group by deptno
)e
where e.r = 1
and emp.deptno = e.deptno
If there happens to be a tie (that is, two or more departments have the same average sal, and it is the highest), then the query above will only arbitrarily treat one of them (no telling which one) as the highest. Change ROW_NUMBER to RANK to get all departments with a claim to having the highest average sal.
You could use the ROWNUM pseudo-column instead of ROW_NUMBER, if all you want to do is avoid ROW_NUMBER.
Without using ROW_NUMBER or RANK, there are lots of ways involving other analytic functions, such as AVG and MAX.
If you really, really don't want to use analytic functions at all, you can do this:
SELECT *
FROM scott.emp
WHERE deptno IN (
SELECT deptno
FROM scott.emp
GROUP BY deptno
HAVING AVG (sal) = (
SELECT MAX (AVG (sal))
FROM scott.emp
GROUP BY deptno
; -
How To Make Search Query Showing the Result As List of Buttons.
Can some one give me an idea how to start to make a Search Query showing the results as list of buttons.. i have already have my buttons with names. i just dont know how to make a search query.
this is my on screen keyboard i made..
im making a system that the result were a list of buttons.. showing like this
This was supposed to be the output of the query that i need to do..
Please help me.. i just need a idea or tips how to make this one.Here is code I posted recently for another question
Public Class Form1
Const BUTTON_SIZE As Integer = 20
Const SPACE As Integer = 5
Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Dim buttons As New List(Of List(Of MyRadioButton))
For row = 1 To 6
Dim newRow As New List(Of MyRadioButton)
buttons.Add(newRow)
For col = 1 To 6
Dim button As New MyRadioButton()
button.row = row
button.col = col
button.Height = BUTTON_SIZE
button.Width = BUTTON_SIZE
button.Left = col * (BUTTON_SIZE + SPACE)
button.Top = row * (BUTTON_SIZE + SPACE)
button.Name = String.Format("radGr1{0}_{1}", row.ToString(), col.ToString())
Me.Controls.Add(button)
newRow.Add(button)
AddHandler button.CheckedChanged, AddressOf Radio_Change
Next col
Next row
End Sub
Private Sub Radio_Change(ByVal sender As Object, ByVal e As System.EventArgs)
Dim button As MyRadioButton = CType(sender, MyRadioButton)
Dim row As Integer = button.row
Dim col As Integer = button.col
End Sub
End Class
Public Class MyRadioButton
Inherits RadioButton
Public row As Integer
Public col As Integer
End Class
jdweng -
Hi,
I am working on AQ where I am just sending and receiving simple messages. But the performance is very poor. It takes around 35 seconds to send (enqueue) just 100 messages which is not acceptable for our project. Can someone help me how to make it more efficient. I am using JMS for sending and receiving messages.
Thanks,
SateeshBhagath,
Thanks for your help.
Oracle server we are using is 8.1.7. We are using JDBC client that ships with Oracle client (classes12.zip).
Right now we are working on point to point messages.
I am just wondering whether I need to do any tuning on server.
Your help is greately appreciated.
Here I am pasting sample code that I wrote which may help in finding the problem.
Thank you so much once again for your help.
-Sateesh
import java.sql.*;
import javax.jms.*;
import java.io.*;
import java.util.Properties;
import oracle.AQ.*;
import oracle.jms.*;
public class CDRQueueSender {
private final String DB_CONNECTION = "jdbc:oracle:thin:@dev1:1521:dev";
protected final String DB_AQ_ADMIN_NAME = "dev78";
private final String DB_AQ_ADMIN_PASSWORD = "dev78";
/** DB AQ user agent name and password */
private final String DB_AQ_USER_NAME = "dev78";
private final String DB_AQ_USER_PASSWORD = "dev78";
private QueueConnectionFactory queueConnectionFactory = null;
private QueueConnection connection = null;
private QueueSession session = null;
private Queue sendQueue;
private QueueSender qSender;
public CDRQueueSender() {
try {
Properties info = new Properties();
info.put(DB_AQ_USER_NAME, DB_AQ_USER_PASSWORD);
queueConnectionFactory = AQjmsFactory
.getQueueConnectionFactory(DB_CONNECTION, info);
connection = queueConnectionFactory.
createQueueConnection(DB_AQ_USER_NAME,
DB_AQ_USER_PASSWORD);
session = connection.createQueueSession(
true, Session.AUTO_ACKNOWLEDGE);
connection.start();
sendQueue = ((AQjmsSession) session).getQueue (DB_AQ_ADMIN_NAME,"CDR_QUEUE");
qSender = session.createSender(sendQueue);
catch (Exception ex) {
ex.printStackTrace();
public boolean sendCDRMessage(CDRMessage messageData)
throws JMSException, SQLException {
ObjectMessage objectMessage = session.createObjectMessage(messageData);
try {
qSender.send(objectMessage);
session.commit();
catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
return true;
public void close() throws JMSException {
session.close();
connection.close();
public static void main(String[] args) throws SQLException, JMSException {
int count = 0;
CDRQueueSender qSender = new CDRQueueSender();
long startTime = System.currentTimeMillis();
long endTime;
CDRMessage message;
while(count < 100) {
message = new CDRMessage("filename", 20, "This is testing", count);
qSender.sendCDRMessage(message);
count++;
//qSender.sessionCommit();
endTime = System.currentTimeMillis();
System.out.println("time taken to process 100 records is " +
((endTime - startTime)/1000) + " seconds");
qSender.close(); -
Could you please help me make this query less complicated
could you please help me make this query less complicated
select t1.R_OBJECT_ID
from dm_relation_sp a, ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID
union all
select t3.R_OBJECT_ID
from ddt_resolution_sp t3
where t3.R_OBJECT_ID in (select t2.child_id
from dm_relation_sp t2
where t2.parent_id in (select a.child_id
from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID))
union all
select t4.R_OBJECT_ID
from ddt_resolution_sp t4
where t4.R_OBJECT_ID in(
select t3.child_id from dm_relation_sp t3
where t3.parent_id in (
select t2.child_id
from asud_fsk.dm_relation_sp t2
where t2.parent_id in (select a.child_id
from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID))
and t3.relation_name = 'RESOLUTION_RELATION')
union all
select t5.R_OBJECT_ID
from ddt_resolution_sp t5
where t5.R_OBJECT_ID in
(select t4.child_id
from dm_relation_sp t4
where t4.parent_id in(
select t3.child_id from dm_relation_sp t3
where t3.parent_id in (
select t2.child_id
from asud_fsk.dm_relation_sp t2
where t2.parent_id in (select a.child_id
from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID))
and t3.relation_name = 'RESOLUTION_RELATION')
and t4.relation_name = 'RESOLUTION_RELATION')
Edited by: user13025450 on 29.04.2010 16:23Hi,
Welcome to the forum! You'll find that there are many qualified people (such as Tubby) willing to help you. Will you do what you can to help them? In order to simplify the query you posted,someone will first have to understand what it does, what the tables that it uses are like, and what tools you have to work with (that is, what version of Oracle, and any other software you are using). To actually test their ideas, people will need versions of your tables.
Many people, if they spent enough time, might be able to figure out roughly what you are doing, make some tables themselves and test a solution. You can help with all of that. I assume you already know what the appliction is, and what this particular query is supposed to do: you don't have to figure out any of that, you just have to say it. You know what all your tables are, what the datatypes of all the columns are, and what kinds of data are in the tables: you don't have to guess at any of that.
Describe what you're doing. Think about it: how do we know that
SELECT NULL
FROM dual;doesn't do what you want?
Post CREATE TABLE and INSERT statements for a little sample data.
Post the results that this query is supposed to produce from those results. (Is it producing the right output now? Then it should be easy to post the correct results.)
Describe, as well as you can, how the present query is doing it.
Format your existing code, so it's easy to see what the different branches of the UNION are, and what the main clauses are in each one.
When posting formatted text (code or results) type these 6 characters
\(all small letters, inside curly brackets) before and after each formatted section, to keep this site from compressing the spaces.
Say what versions of Oracle (e.g. 10.2.0.3.0) and any other relevant software you are using.
I know it's a lot of work, but it really helps. You can do it as well (probably better) than anyone else, and if you're unwilling to do it, why should anyone else be willing? -
Something keeps trying to download on my mac and I don't know what it is. It is not in the apple store and just comes out nowhere and request for my password to download something and I don't know what it is. How to make this stop? It pops up every single day.
Erica,
I can, with 99.99% certainty, tell you that you are absolutely right in not wanting to download or install this "Helper," whatever it is (but we can be equally certain it would not "help" anything).
I cannot comment as to Oglethorpe's recommendation of 'adwaremedic'; I am unfamiliar with it. His links to the Apple discussion and support pages warrant your time and attention.
It might be really simple -- Trying looking in your Downloads folder, trash anything that you don't know with certainty is something you want to keep, and then Secure Empty your Trash. Then remove the AdBlock extension, LastPass, and Web of Trust extensions to Safari and re-boot. If the issue goes away, still be extraordinarily careful in the future.
Unfortunately, it's probably not going to be that simple to get rid of, in which case I'd then try the line by line editing in HT203987.
I have no further suggestions (other than a complete wipe and re-install...but that's a pain because trying to restore from Time Machine would simply ... restore the Mal).
For the rest of us, please post when you find a solution.
Best.
BPW
(Also, try to edit your second post -- black out your last name on the screenshot and re-post it for others)
Maybe you are looking for
-
I had imported hundreds of loops into my version of soundtrack (the ancient 1.2) and painstakingly labeled them by genre and descriptors. I had a computer crash (but have an exact clone of the crashed hard drive) although all of the loops are back in
-
I know this has been covered many times, but I couldn't find answers better than smartview is catching up. We are on 11.1.2.3.502 (I know the add-in is not supported for the version but we still use it) I have a sheet where when I retrieve results it
-
Mavericks does not detect my HD tv via thunderbolt
I have a 15" Macbook Pro (mid 2012) and when I plug in my thunderbolt to hdmi adapter it does not detect it at all. Also I am running Mavericks on this Macbook. Please Help
-
Recently, I got a new desktop. I was just going to move the old hard drive into the new computer as a secondary, but we couldn't remove the drive. So we copied the information over. Now, I was worried about playlists and edits I had made to track inf
-
Why did they remove the second alert for Calendars ??
I saw that this software update has taken away the second alert that could be added to calendar entries ? Why would they do that ?