Join query for three tables
Hi i have got this query that is a join of two tables but i need join for three tables i need the extended query
select aauthlname aauthlnam aauthfname aauthfnam aisbn btitle
from ( bsauthors as a inner join bsbook as b on aisbn = bisbn )
into corresponding fields of table books
where aauthlname like authorlname or aauthfname like authorfname
order by aauthlname aauthfname a~isbn.
Hi pavan
Plz try the following querry for joins on three tables :
" Customize it to ur requirements and tablenames
Parameters : b type mara-matnr.
select xmatnr xmtart xmatkl ywerks ylgort zmaktx
into corresponding fields of table itab
from ( ( mara as x inner join mard as y on xmatnr = ymatnr )
inner join makt as z on xmatnr = zmatnr ) where x~matnr = a and
y~werks
= b .
Plz see that there is atleast one field common between the three tables u want to use.
Regards
Pankaj
Similar Messages
-
dear friends
kna1- kunnr ,name1
vbak - vbeln , erdat
vbap - meins , kwmeng
on above i have given three tables and their fields in front of this
can any one tel me how to give inner join in select statement for the above tablesHi Create an appropriate internal table ITAB
Select VBAK~VBELN
VBAK~ERDAT
VBAP~POSNR
VBAP~MEINS
VBAP~kwmeng
KNA1~KUNNR
KNA1~NAME1
From VBAK
Into Table ITAB
Inner Join VBAP On VBAKVBELN = VBAPVBELN
Inner Join KNA1 On VBAK~KUNNR = KNA1-KUNNR
Where VBAK~VBELN In S_VBELN.
Santhosh -
More than one join condition for 2 tables in obiee
Hello,
I am using obiee 11g.
There are 2 tables tableA and tableB where the join condition is like (tableA.col1=tableB.col1) or (tableA.col1 is null and tableB.col1 is null)
where should i do these type of joins.
I tried putting in physcial layer->f(x) but giving error like here only columns an d opertaors are allowed.
Thanksok here it goes.
I have a tableA with columns col1(pk),col2 and other columns
I have tableB with columns col1(pk),col2..Only these 2 columns.
Now distinct tableA.col2 values are put in tableB.col2. For those distinct values i have put the tableB.col1 values.
Now tableA.col2 as well as tableB.col2 can be null beacuse there may be null values in tableA.col2.
Now in tableB i have added one more row which has col1 as value and col2 as null.
Now when in physical layer when i do tableA.col2=tableB.col2 i dont get the null values.
What i want is whenever the tableA.col2 and tableB.col2 is null then take tableB.col1 for those vales.
So when i query i do
select * from tableA,tableB where
((tableA.col2=tableB.col2) or (tableA.col2 is null and tableB.col2 is null))
What i want is when i do a join i should be able to give this OR condition in rpd thats it.
because when i do in where clause of content tab it goes like a AND condition and not OR.
Thanks
Edited by: user123 on Jul 5, 2011 1:57 PM -
Tuning SQL Query for base tables
Hi,
Can any please help me to tune the below query...... there is full table scan for po_action_history table
SELECT DISTINCT
DECODE(hr.full_name,'Default Buyer, Purchasing','PCH',
'Default Buyer, Travel','TRV',
'Purchase Order, Rapid','RPO',
'Data Interchange, Electronic','EDI',fuser1.user_name) BUYER_ID,
poa.attribute1 BUYER_GROUP,
poa.attribute2 BUYER_SUBGROUP
FROM po.po_action_history ac1,
po.po_headers_all ph,
po.po_agents poa,
hr.per_all_people_f hr,
applsys.fnd_user fuser1
WHERE ph.po_header_id = ac1.object_id
AND ac1.object_type_code = 'PO'
AND ac1.action_code = 'APPROVE'
AND sequence_num =(SELECT MIN(ac2.sequence_num)
FROM po.po_action_history ac2,
applsys.fnd_user fuser2
WHERE ph.po_header_id = ac2.object_id
AND ac2.object_type_code = 'PO'
AND ac2.action_code = 'APPROVE'
AND ac2.last_updated_by = fuser2.user_id)
--AND ac1.last_updated_by = fuser1.user_id
AND ph.agent_id = poa.agent_id
AND ph.agent_id = hr.person_id
AND hr.person_id = fuser1.employee_id
AND hr.effective_end_date > sysdate
AND trunc(ac1.last_update_date) between '01-JAN-08' and '07-JAN-08'
ORDER BY poa.attribute1
Explain Plan
PLAN_TABLE_OUTPUT
Plan hash value: 3325319312
Id Operation Name Rows
Bytes Cost (%CPU) Time
PLAN_TABLE_OUTPUT
| 0 | SELECT STATEMENT | | 27 |
2754 | 38963 (3) | 00:07:48 |
| 1 | SORT UNIQUE | | 27 |
2754 | 38962 (3) | 00:07:48 |
|* 2 | FILTER | | |
| | |
|* 3 | HASH JOIN | | 37 |
3774 | 36308 (3) | 00:07:16 |
PLAN_TABLE_OUTPUT
| 4 | TABLE ACCESS BY INDEX ROWID | FND_USER | 1 |
13 | 2 (0) | 00:00:01 |
| 5 | NESTED LOOPS | | 37 |
3293 | 36303 (3) | 00:07:16 |
| 6 | NESTED LOOPS | | 88 |
6688 | 36180 (3) | 00:07:15 |
| 7 | NESTED LOOPS | | 88 |
PLAN_TABLE_OUTPUT
3960 | 35916 (3) | 00:07:11 |
|* 8 | TABLE ACCESS FULL | PO_ACTION_HISTORY | 2110 |
71740 | 32478 (3) | 00:06:30 |
| 9 | TABLE ACCESS BY INDEX ROWID | PO_HEADERS_ALL | 1 |
11 | 2 (0) | 00:00:01 |
|* 10 | INDEX UNIQUE SCAN | PO_HEADERS_U1 | 1 |
| 1 (0) | 00:00:01 |
PLAN_TABLE_OUTPUT
| 11 | SORT AGGREGATE | | 1 |
36 | | |
| 12 | NESTED LOOPS | | 1 |
36 | 6 (0) | 00:00:01 |
|* 13 | TABLE ACCESS BY INDEX ROWID| PO_ACTION_HISTORY | 1 |
31 | 6 (0) | 00:00:01 |
|* 14 | INDEX RANGE SCAN | PO_ACTION_HISTORY_N1 | 5 |
| 3 (0) | 00:00:01 |
PLAN_TABLE_OUTPUT
|* 15 | INDEX UNIQUE SCAN | FND_USER_U1 | 1 |
5 | 0 (0) | 00:00:01 |
| 16 | TABLE ACCESS BY INDEX ROWID | PER_ALL_PEOPLE_F | 1 |
31 | 3 (0) | 00:00:01 |
|* 17 | INDEX RANGE SCAN | PER_PEOPLE_F_PK | 1 |
| 2 (0) | 00:00:01 |
|* 18 | INDEX RANGE SCAN | FND_USER_N1 | 1 |
PLAN_TABLE_OUTPUT
| 1 (0) | 00:00:01 |
| 19 | TABLE ACCESS FULL | PO_AGENTS | 183 |
2379 | 4 (0) | 00:00:01 |
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
2 - filter(TO_DATE('01-JAN-08')<=TO_DATE('07-JAN-08'))
3 - access("PH"."AGENT_ID"="POA"."AGENT_ID")
8 - filter("AC1"."ACTION_CODE"='APPROVE' AND "AC1"."OBJECT_TYPE_CODE"='PO'AND
TRUNC(INTERNAL_FUNCTION("AC1"."LAST_UPDATE_DATE"))>='01-JAN-08' AND
TRUNC(INTERNAL_FUNCTION("AC1"."LAST_UPDATE_DATE"))<='07-JAN-08')
10 - access("PH"."PO_HEADER_ID"="AC1"."OBJECT_ID")
PLAN_TABLE_OUTPUT
filter("SEQUENCE_NUM"= (SELECT MIN("AC2"."SEQUENCE_NUM") FROM "APPLSYS"."FND_USER"
"FUSER2","PO"."PO_ACTION_HISTORY" "AC2" WHERE "AC2"."OBJECT_ID"=:B1 AND "AC2"."ACTION_CODE"='APPROVE'
AND "AC2"."OBJECT_TYPE_CODE"='PO' AND "AC2"."LAST_UPDATED_BY"="FUSER2"."USER_ID"))
13 - filter("AC2"."ACTION_CODE"='APPROVE' AND "AC2"."OBJECT_TYPE_CODE"='PO')
14 - access("AC2"."OBJECT_ID"=:B1)
PLAN_TABLE_OUTPUT
15 - access("AC2"."LAST_UPDATED_BY"="FUSER2"."USER_ID")
17 - access("PH"."AGENT_ID"="PERSON_ID" AND "EFFECTIVE_END_DATE">SYSDATE@!)
filter("EFFECTIVE_END_DATE">SYSDATE@!)
18 - access("PERSON_ID"="FUSER1"."EMPLOYEE_ID")
ThanksHi,
any help for the above issue. -
Hi,
I have this problem, How can query a two table?
Table A -> Table B
id table-a_id
name table_b_name
the relationship is one-to-many
How can I get the result?
Hope my question make sense
cheers.
thanks a lot.I bet you have more luck looking for an answer in a SQL forum.
-
Need a query for export table data .....
Hi,
I need a query for exporting the data in a table to a file.
Can anyone help me ?
Thanking You
JeneeshSQL> spool dept.txt
SQL> select * from dept;
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> spool off
SQL> ed dept.txt -
Problem when doing inner join for three tables....
DATA: V3 TYPE VBAP-MAKTL.
SELECT single vbap~matkl into V3
from VBAP
inner join VBFA
inner join LIPS
on LIPSPOSNR = VBFAPOSNN
and vbapvbeln = vbfavbelv
and vbapposnr = vbfaposnv
where LIPSVBELN = VBFAVBELN = '0080000834'
and vbfa~vbtyp_n = 'J'
and LIPS~J_3ASIZE = '0884'.
Error: Wrong expression "INNER" in from clause...Hello Tushar,
Why you are using the 3 table inner join. If the volume of data is big then this statement will give to time out. Use "for all entries" statement to select the data from the table.
Like
select field1 field2 from LIPS into i_lips
where LIPS~J_3ASIZE = '0884'.
select f3 f4 from vbfa into i_vbfa for all entries in i_lips where field1 = i_lips-field1 and so on
and
use same to select data from VBAP.
Hope this will help -
Outer join query for SQL server from Oracle
Hi All,
My question is regarding making queries from Oracle to SQL Server database thorugh DBLink.
In my oracle database I have a DBLink emp.world for SQL Server database.
I need to query SQL Server data from oracle (so that this query can be combined with other oracle tables).
Query is given below:
SELECT
a."EmpID" as "Employee ID",
a."EmpStatus" "Employee Status"
b."EmpSub" as "Employee Subjects"
FROM
[email protected] a
left outer join [email protected] b on a."EmpID" = b."suEmpID"
ORDER BY a."EmpID";My problem is when I run the same query from oracle, it does not show the EmpID that does not exist in Subjects table, but when run from actual SQL Server database, it shows all the records.
Samples are given below:
Run from Oracle
Employee ID Employee Status Employee Subjects
101 Active Maths
102 Active Maths
102 Active Physics
104 Inactive Chemistry
Run form SQL Server
Employee ID Employee Status Employee Subjects
101 Active Maths
102 Active Maths
102 Active Physics
103 Active NULL
104 Inactive ChemistryI am not sure why in oracle outer join for SQL server tables is not working. What is the right way for outer join in this case.
I am using oracle database 10gR2 and SQL Server 2005.
Please Help.
Thanks.SELECT
a."EmpID" as "Employee ID",
a."EmpStatus" "Employee Status"
b."EmpSub" as "Employee Subjects"
FROM
[email protected] a
left outer join [email protected] b on a."EmpID" = b."suEmpID"
ORDER BY a."EmpID";
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm#sthref3175
From your description, it appears you may need a right outer join. You want to get back all the rows from 'B', not from 'A'. Try a right join and let us know. -
Hi,
I need to write a SELECT statement that returns one row for each customer that has orders with the following columns:
======================================================================
Email addresses from Customers Table
Sum of the Item Price in the OrdersItems table multiplied by the quantity in the
OrderItems table
Sum of the discount amount column in the OrderItems table multiplied by the quantity in the OrderItems Table.
Sort the results set in the descending sequence by the item price total for each customer.
===================================================================
Customers table has no connection with Orderitems table, so it has to go through ORDERS table. I have written the following query. Can someone check and give me a feed back? It is not giving me the correct output. This should be the output:
Email address
ItemPriceTotal DiscountAmountTotal
[email protected] 4131.00
1830.30
etc, etc........
My code is not adding the above columns correctly. I have tried SUM for Total columns but gives me errors:
SELECT EmailAddress, ItemPrice * Quantity AS ItemPriceTotal, DiscountAmount * Quantity AS DiscountAmountTotal
FROM
Customers
JOIN ORDERS
ON CUSTOMERS.CustomerID = Orders.CustomerID ----Joins Orders with Customers
JOIN OrderItems
ON Orders.OrderID = OrderItems.OrderID; ------ Joins Orders with OrderItems
----ORDER BY EmailAddress,ItemPriceTotal; ( tried Order by, but output is not correct)Thank you for your help. I really appreciate it. My output should look like this, but my query is not adding the ItemPriceTotal and DiscountAmountTotal:
Results:
EmailAddress
ItemPriceTotal
DiscountAmountTotal
[email protected]
4131.00
1830.39
[email protected]
2398.00
719.40
[email protected]
2198.98
659.70
[email protected]
998.00
209.70
[email protected]
799.99
120.00
[email protected]
489.99
186.20
[email protected]
299.00
0.00 -
[Help] Join query from 3 tables
Hi, I'm new to database. I have a question about joining 3 tables, pardon me for my bad english.
My tables look like this
table 1: Person (id,firstname, lastname)
table 2: AssignPersonAddress (id,personid,addressid,type)
table 3: Address (id,telefon, street, etc)
I need AssignPersonAddress table, because in my data structure a person can have more than 1 address and the address type should be saved (for eg: private, work)
I want to make a select query to report all of person with his private telefon and work telefon, like this.
PERSON | PRIVATE | WORK
At the moment my query looks like this
select p.name , a1.tel AS Private, a2.tel AS Work
from person p,
addresse a1 ,
AssignPersonAddress apd1,
AssignPersonAddress apd2,
addresse a2
where p.id = apd1.person (+)
and apd1.adresse = a1.id
and apd1.art = 'Private'
and p.objectid = apd2.person (+)
and apd2.adresse = a2.id
and apd2.art = 'Work'the problem is I only get the person who has private and work address. But what I want is all person no matter if the person has only 1 address or 2 address.
As you can see I put the outer left join at the where condition, but I'm still getting the wrong result.
thx in advance
Danny
Edited by: raitodn on Oct 1, 2009 3:51 AM
Edited by: raitodn on Oct 1, 2009 4:12 AMHi,
You're essentially doing an inner join, because some of the comparisons are missing the + markerr.
Do this instead:
select p.name , a1.tel AS Private, a2.tel AS Work
from person p
, addresse a1
, AssignPersonAddress apd1
, AssignPersonAddress apd2
, addresse a2
where p.id = apd1.person (+)
and apd1.adresse = a1.id (+)
and apd1.art (+) = 'Private'
and p.objectid = apd2.person (+)
and apd2.adresse = a2.id (+)
and apd2.art (+) = 'Work'
;What does this mean?
where p.id = apd1.person (+)It means "include rows from p even if they don't have any matching rows in apd1". Whenever that happens, all the colummns from apd1 will be NULL.
So far, so good.
Now, what happens if you follow that with
and apd1.adresse = a1.id The condition above means "include this row from apd1 only if there is matching row in a1". If apd1 is NULL, this condition will never be TRUE (even if a1.id is NULL).
When you do a cascading outer join like this, all columns in the distal table (the table farther away from the table that must be present) need to be marked with the + sign. That includes conditions involving a constant, like
and apd1.art (+) = 'Private' By the way, when posting code or results on this site, always type these 6 characters:
(small letters only, inside curly brackets) to preserve spacing and to keep some strings, such as the outer-join marker, form being interpreted as emoticons.
Edited by: Frank Kulash on Oct 1, 2009 6:37 AM
Added explanation -
Syntax check in a join query for detecting max,min cardinalities
Hello my friends
i wrote a query i just want to know if its syntax is correct or not?if possible please rewrite it for me.thank u in advance.
geo_mountain: mountain,country,province
province: name,country,population,area,capital,capprov
mountain: name,height
in fact i want to detect max and min cardinalities between province and mountain.
every mountain is is how many provinces?min and max
every mountain has how many mountain? min and max
select max(select count(*) from province,geo_mountain where provice.name=geo_mountain.provice group by province.name) from province,geo_mountain as MAX_MONTAINS_IN_A_PROVINCE;
select min(select count(*) from province p join geo_mountain geo on p.name=geo.province group by p.name) from province,geo_mountain as MIN_MONTAINS_IN_A_PROVINCE;
select max(select count(*) from mountain m join geo_mountain geo on m.name=geo.mountain group by m.name) from province,geo_mountain as MAX_PROVINCES_OF_A_MOUNTAIN;
select min(select count(*) from mountain m join geo_mountain geo on m.name=geo.mountain group by m.name) from province,geo_mountain as MAX_PROVINCES_OF_A_MOUNTAIN;
-- File created - Thursday-May-02-2013
-- DDL for Table PROVINCE
CREATE TABLE "intern"."PROVINCE" ("NAME" VARCHAR2(40), "COUNTRY" CHAR(2), "POPULATION" NUMBER, "AREA" NUMBER, "CAPITAL" VARCHAR2(40), "CAPPROV" VARCHAR2(40))
COMMENT ON COLUMN "intern"."PROVINCE"."NAME" IS 'the name of the administrative division'
COMMENT ON COLUMN "intern"."PROVINCE"."COUNTRY" IS 'the country code where it belongs to'
COMMENT ON COLUMN "intern"."PROVINCE"."POPULATION" IS 'the population of the province'
COMMENT ON COLUMN "intern"."PROVINCE"."AREA" IS 'the total area of the province'
COMMENT ON COLUMN "intern"."PROVINCE"."CAPITAL" IS 'the name of the capital'
COMMENT ON COLUMN "intern"."PROVINCE"."CAPPROV" IS 'the name of the province where the captital belongs to'
COMMENT ON TABLE "intern"."PROVINCE" IS 'information about administrative divisions'
REM INSERTING into intern.PROVINCE
SET DEFINE OFF;
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Anhui','cn',73059713,139057,'Hefei','Anhui');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Aomen','cn',482581,24,'Aomen','Aomen');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Chongqing','cn',32344010,82403,null,null);
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Fujian','cn',34062204,123603,'Fuzhou','Fujian');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Gansu','cn',26316859,464186,'Lanzhou','Gansu');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Guangdong','cn',77333529,177933,'Guangzhou','Guangdong');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Guangxi','cn',49443331,241410,'Nanning','Guangxi');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Guizhou','cn',38090358,176505,'Guiyang','Guizhou');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Hainan','cn',7940197,34353,'Haikou','Hainan');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Hebei','cn',68949170,187991,'Shijiazhuang','Hebei');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Heilongjiang','cn',37073415,432477,'Harbin','Heilongjiang');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Henan','cn',94811791,166499,'Zhengzhou','Henan');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Hong Kong','cn',6983938,1085,'Victoria','Hong Kong');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Hubei','cn',61263368,185125,'Wuhan','Hubei');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Hunan','cn',67787707,211836,'Changsha','Hunan');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Jiangsu','cn',72117460,97607,'Nanjing','Jiangsu');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Jiangxi','cn',42590186,167430,'Nanchang','Jiangxi');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Jilin','cn',27402930,192105,'Changchun','Jilin');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Liaoning','cn',41699162,147785,'Shenyang','Liaoning');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Neimenggu','cn',24433946,1218698,'Hohhot','Neimenggu');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Ningxia','cn',6234044,55461,'Yinchuan','Ningxia');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Peking','cn',11653700,16808,null,null);
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Qinghai','cn',4928342,716693,'Xining','Qinghai');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Shaanxi','cn',36881993,205693,'Xian','Shaanxi');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Shandong','cn',92163194,156867,'Jinan','Shandong');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Shanghai','cn',13355925,6341,null,null);
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Shanxi','cn',34024073,157023,'Taiyuan','Shanxi');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Sichuan','cn',86421728,491146,'Chengdu','Sichuan');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Tianjin','cn',9338819,11632,null,null);
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Tibet','cn',2630000,1228400,'Lhasa','Tibet');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Xinjiang','cn',19514731,1774034,'Urumqi','Xinjiang');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Xizang','cn',2610891,1268947,'Lasa','Xizang');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Yunnan','cn',41997191,393734,'Kunming','Yunnan');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Zhejiang','cn',46354322,103900,'Hangzhou','Zhejiang');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Amazonas','co',80360,109665,'Leticia','Amazonas');
Insert into intern.PROVINCE (NAME,COUNTRY,POPULATION,AREA,CAPITAL,CAPPROV) values ('Antioquia','co',5750478,63612,'Medellin','Antioquia');
-- File created - Thursday-May-02-2013
-- DDL for Table MOUNTAIN
CREATE TABLE "intern"."MOUNTAIN" ("NAME" VARCHAR2(30), "HEIGHT" NUMBER, "COORDINATES" "intern"."GEOCOORD" )
COMMENT ON COLUMN "intern"."MOUNTAIN"."NAME" IS 'the name of the mountain'
COMMENT ON COLUMN "intern"."MOUNTAIN"."HEIGHT" IS 'the height of the mountain'
COMMENT ON COLUMN "intern"."MOUNTAIN"."COORDINATES" IS 'its geographical coordinates as (longitude, latitude)'
COMMENT ON TABLE "intern"."MOUNTAIN" IS 'information about mountains'
REM INSERTING into intern.MOUNTAIN
SET DEFINE OFF;
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Bjelucha',4506);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Istor-o-Nal',7403);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Jabal Marra',3088);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Jezerce',2694);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Joekul',1876);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Jongsong Peak',7483);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Jostedalsbre',2083);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('K12',7428);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('K2',8614);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Kangchenjunga',8586);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Khunyang Chhish',7852);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Kilimanjaro',5895);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Kinabalu',4101);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Kings Peak',4123);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Kongur Tagh',7649);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Kongur Tjube',7595);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Korab',2751);
Insert into intern.MOUNTAIN (NAME,HEIGHT,COORDINATES) values ('Kula Kangri',7538);
-- File created - Thursday-May-02-2013
-- DDL for Table GEO_MOUNTAIN
CREATE TABLE "INTERN"."GEO_MOUNTAIN" ("MOUNTAIN" VARCHAR2(30), "COUNTRY" CHAR(2), "PROVINCE" VARCHAR2(40))
COMMENT ON COLUMN "INTERN"."GEO_MOUNTAIN"."MOUNTAIN" IS 'the name of the mountain'
COMMENT ON COLUMN "INTERN"."GEO_MOUNTAIN"."COUNTRY" IS 'the country code where it is located'
COMMENT ON COLUMN "INTERN"."GEO_MOUNTAIN"."PROVINCE" IS 'the province of this country'
COMMENT ON TABLE "INTERN"."GEO_MOUNTAIN" IS 'geographical information about mountains'
REM INSERTING into INTERN.GEO_MOUNTAIN
SET DEFINE OFF;
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Minya Konka','cn','Sichuan');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Broad Peak','cn','Xinjiang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Gasherbrum I','cn','Xinjiang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Gasherbrum II','cn','Xinjiang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('K2','cn','Xinjiang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Kongur Tagh','cn','Xinjiang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Kongur Tjube','cn','Xinjiang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Muztagh Ata','cn','Xinjiang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Peak Pobeda','cn','Xinjiang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Sia Kangri','cn','Xinjiang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Skilbrum','cn','Xinjiang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Skyang Kangri','cn','Xinjiang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Teram Kangri','cn','Xinjiang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Changtse','cn','Xizang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Cho Oyu','cn','Xizang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Chomo Lonzo','cn','Xizang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Ganesh','cn','Xizang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Gangkhar Puensum','cn','Xizang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Gurla Mandhata','cn','Xizang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Gyachung Kang','cn','Xizang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Jongsong Peak','cn','Xizang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Kula Kangri','cn','Xizang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Lhotse','cn','Xizang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Makalu','cn','Xizang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Mount Everest','cn','Xizang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Mount Godwin Austen','cn','Xizang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Namcha Barwa','cn','Xizang');
Insert into INTERN.GEO_MOUNTAIN (MOUNTAIN,COUNTRY,PROVINCE) values ('Shishapangma','cn','Xizang');im using oracle11g and ubuntu 12,4
thank u in advance.
best,
davidIn that case you need to do a Outer join. A Inner join will still give the same result.
Something like this
select min(cnt) min_count, max(cnt) max_count
from (
select geo.mountain, count(distinct province) cnt
from mountain m
left join geo_mountain geo
on geo.mountain=m.name
group by m.name
select min(cnt) min_count, max(cnt) max_count
from (
select geo.province, count(distinct mountain) cnt
from province p
left join geo_mountain geo
on p.name=geo.province
group by geo.province
);Edited by: Karthick_Arp on May 2, 2013 3:51 AM
Added query -
Inner Join Condition For Database Tables in JDBC Adapter
Hi
Is there any restriction for Number of database tables to Write Inner join Condition in JDBC.
ThanksVenkat,
No there is no restriction in Inner join. If your query executes perfectly in target Database then the same query will exceute perfectly while calling through XI.
Best regards,
raj. -
Design
Table Name Field Name Data Type Allow Null Reference
Employee
ID Int No
Name Varchar(20) No
ID_Department Int No Department.ID
ID_Manager Int Yes Employee.ID
Salary Int No
Bonus Numeric(6,2) Yes
Department
ID Int No
Name Varchar(20) No
Awards
ID_Employee Int No Employee.ID
ID_Manager Int No Employee.ID
NoOfAwards TinyInt No
Data
Employee
ID Name ID_Department ID_Manager Salary Bonus
1 Mohan 3 NULL 25000 0
2 Chintan 3 1 15000 0
3 Ajay 2 2 10000 0
4 Vipul 2 3 7500 0
5 Rohini 1 2 5000 0
Department
ID Name
1 Computer
2 Account
3 Sales
4 HR
Awards
ID_Employee ID_Manager NoOfAwards
2 1 4
3 2 5
5 3 2
4 3 2
3 1 3
Note:
1 Manager of any employee is also an employee of a company.
2 Employee with ID_Manager = NULL is a BOSS/OWNER. (e.g. Mohan)
3 "[Awards] table represents No.of Awards won by an employee with combination of other employee as a manager which could be other than his actual manager also.
e.g. Rohini(as an employee) has won 2 awards while working with Ajay(as a Manager)
e.g. Mohan as an employee can not win award with other employee as a Manager but he can win award as a Manager with other employee"
1 "Update the bonus of all employees => (total salary of all employees of that employee's department) x (Number of employees under that employee)%
Note: Employee who is not a Manager should get 0.5% of total salary of all employees of his department"
"e.g. Chintan should get (total of his Department)*(Chintan is manager of 2 employees)% => 40000*2% = 800.
e.g. Rohini is not a manager of any employee so he should get (total of his Department)*0.5% => 5000 * 0.5% = 25"
2 List out all employee names and Total Number of Awards won as an Employee and Total Number of Awards won as a Manager.Hi,
in any case assuming that you have the following structure under Oracle:
CREATE TABLE department
id INT NOT NULL
, name VARCHAR (50) NOT NULL
, CONSTRAINT pk_department PRIMARY KEY (id)
CREATE TABLE employee
id INT NOT NULL
, name VARCHAR (50) NOT NULL
, id_department INT NOT NULL
, id_manager INT NULL
, salary INT NOT NULL
, bonus NUMERIC (6, 2) NOT NULL
, CONSTRAINT pk_employee PRIMARY KEY (id)
, CONSTRAINT fk_departmentno FOREIGN KEY
(id_department)
REFERENCES department (id)
CREATE TABLE awards
id_employee INT NOT NULL
, id_manager INT NOT NULL
, noofawards INT NOT NULL
);To get the bonus as you want calculated you can do:
MERGE INTO employee emp
USING (SELECT id
, salary
, (SELECT COUNT (*)
FROM employee
WHERE id_manager = e.id) cnt
, (SELECT SUM (salary)
FROM employee
WHERE id_department = e.id_department) dept_tot_sal
FROM employee e) src
ON (emp.id = src.id)
WHEN MATCHED
THEN
UPDATE SET bonus = src.dept_tot_sal * DECODE (cnt, 0, 0.5, cnt) / 100;
SELECT * FROM employee;
ID NAME ID_DEPARTMENT ID_MANAGER SALARY BONUS
1 Mohan 3 25000 400
2 Chintan 3 1 15000 800
3 Ajay 2 2 10000 175
4 Vipul 2 3 7500 87.5
5 Rohini 1 2 5000 25However I see a contradiction in your calculation. Mohan is getting a lower bonus than Chintan if we are considering only employees under him at first level. If you want to consider all employees under him (considering the whole hierarchy) then you could modify the part which is calculating the count of employees in this way:
, ( SELECT COUNT (*)
FROM employee
START WITH id_manager = e.id
CONNECT BY PRIOR id = id_manager) cntFor what is regarding question number 2 here the query you could use:
SELECT e.id, e.name, NVL (SUM (awe.noofawards), 0) awards_as_employee
, NVL (SUM (awm.noofawards), 0) awards_as_manager
FROM employee e
LEFT OUTER JOIN awards awe
ON (e.id = awe.id_employee)
LEFT OUTER JOIN awards awm
ON (e.id = awm.id_manager)
GROUP BY e.id, e.name;
ID NAME AWARDS_AS_EMPLOYEE AWARDS_AS_MANAGER
2 Chintan 4 5
4 Vipul 2 0
5 Rohini 2 0
3 Ajay 16 8
1 Mohan 0 7As you haven't posted the expected result for this second query I don't know if you want to consider only one level as manager or walk through the whole tree.
Regards.
Al -
Need a query for access tables
Hi
I need a query , help please:
table1:
id description serial
1 des1 ser1
2 des2 ser2
3 des3 ser3
table2:
id id1(id of table1) date
stat
1 1
2001 A
2 1
2008 N
3 2
2010 A
4 1
2012 F
==============
i need this data structure: (stat column must return for maximum date of id1 from table2)
id(from table1) serial(from table1) stat(from table2)
1 ser1
2012
2 ser2
2010
3 ser3
Nullmaybe you can try this.
declare @t1 table
(id int,[description] varchar(50),serial varchar(10))
declare @t2 table
(id int,id1 int,[date] char(4),stat char(10))
insert into @t1 values
(1,'des1','ser1'),
(2,'des2','ser2'),
(3,'des3','ser3')
insert into @t2 values
(1,1,'2001','A'),
(2,1,'2008','N'),
(3,2,'2010','A'),
(4,1,'2012','F')
select a.id,a.serial,max(b.date)
from @t1 a
left join @t2 b
on a.id = b.id1
group by a.id,a.serial
| SQL PASS Taiwan Page |
SQL PASS Taiwan Group
|
My Blog -
How to use dynamic query for Result table
Hello Experts,
I want to use dynamic query and then display the result in the assignment block.
Using dynamic query BTQAct and BTQRAct and base on some search criteria i want tofilter and then append the result in the result table of that custom context node, and then it should display the result in the view in UI.
SO can you please provide me the samplle code on how to use the dynamic query and append in the result table.
Regards.Hi,
Please find below sample code:
data: query TYPE REF TO cl_crm_bol_dquery_service,
result TYPE REF TO if_bol_bo_col.
DATA: lt_params TYPE crmt_name_value_pair_tab,
lwa_params TYPE crmt_name_value_pair.
query = cl_crm_bol_dquery_service=>get_instance( 'BTQAct' ). " Get instance of dynamic query
Set general query parameter for maximum number of hits
lwa_params-name = 'MAX_HITS' .
lwa_params-value = '50'.
APPEND lwa_params TO lt_params.
query->set_query_parameters( it_parameters = lt_params ).
query->add_selection_param( iv_attr_name = 'OBJECT_ID'
iv_sign = 'I'
iv_option = 'EQ'
iv_low = <lv_objectid>
iv_high = '' ). " Set your search criteria. Repeat this code if you have multiple parameters
"You can find possible search options for a query object in GENIL_BOL_BROWSER
result ?= query->get_query_result( ). " Get result from your search query
me->typed_context-> <your result context node>->set_collection( result ).
Here you will have to create a context node in your view which would refer to query result object like for BTQAct its BTQRAct
Hope this helps.
e Regards,
Bhushan
Maybe you are looking for
-
Error while cloning database using RMAN
hi there, Here is our setup: OS: Solaris 5.9 Database:9.2.0.3 While cloning test database from our production database using RMAN, we happen to get the following error.. RMAN-00571: =========================================================== RMAN-005
-
We get the following message once a month "We're sorry, the billing information on file could not be used for this payment. Please update your billing information." - Every month. No card declines, no authorizations. No matter how many times we inp
-
Iphoto11 9.2.3 crashes
25 crashes so far...and senior advisors cant get not even one single feedback from tech engineers,.... here the most recent crash log, but before a console log showing the few lines during the most recent crash: here the console: 6/24/12 7:17:42.000
-
Hello all. I'm still working on Books vs. Teams. Is there a way when an Account record is loaded (imported or via web service) that the Book assignment can run automatically? This would similar to setting the Reassign Account checkbox when loading re
-
Is there a GRC Demo/Test Instance Available on the Net?
Is there a GRC Demo/Test Instance Available on the Net?