Gites join Question!
Hi guys,.I need a report that displays the comm total of 'sale' and the total of the "rent" comm
Based on the following table.
Transaction Type Total Comm
62 - 1000 SALE
61 9 APRIL 11 - RENT 500
63 - SALE 1000
41 16 APR 11 - RENT 500
--
Best regards
Hello
You can do this with a self-join, but it is much more effective to do it like this:
SELECT SUM (CASE WHEN type = 'SALE' THEN comm END) AS total_sale
, SUM (CASE WHEN type = 'RENT' THEN comm END) AS total_rent
FROM table_x
WHERE type IN ('RENT', 'SALE')
-- GROUP BY ... -- If wanted
;
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements), and the results you want from this data.
Explain how you get these results from these data.
Always tell what version of Oracle you are using.
Tags: Database
Similar Questions
-
Join question / unlink you domain Windows 8
I recently performed a clean installation of Windows 8 without problem. I tried to join to a domain. Everything seems to work as expected and I even got the standard windows of information indicating that I have was greeted at the field and I had to restart. After the reboot, I am unable to log on to the domain and I get a message indicating that the trust relationship is broken. Unfortunately, I can't use my local admin account either... the system is telling me no matter what I try to do requires high privileges which I am unable to access the connection with the Act that the workstation has not correctly joined to the domain. In addition, for the domain controller, I can not find a computer account for this system. Is there an easy way to separate this pc "is not entirely-joints" the domain and return it to a State of "stand alone" so I can try to join again? Thanx.
Hello
For the Domain Join questions, I recommend that ask you this question on the following forums.
Windows 8 IT Pro category:
http://social.technet.Microsoft.com/forums/en-us/category/w8itpro
Concerning
-
Gites join vs hierarchical queries
Hello
Please tel me who must use a 1?
I have to get job list of the simple Manger, should I use self-join or hierarchical queries (CONNECT BY and earlier versions)?
Yours sincerelyHello
944768 wrote:
HelloPlease tel me who must use a 1?
I have to get job list of the simple Manger, should I use self-join or hierarchical queries (CONNECT BY and earlier versions)?It depends on your data and your needs.
Whenever you have a question, please post a small example of data (CREATE TABLE and INSERT statements) for all the tables involved, so people who want to help you can recreate the problem and test their ideas. Also post the results you want from this data, as well as an explanation of how you get these results from these data.
Explain, using specific examples, how you get these results from these data.
If you show what the problem using commonly available tables (suc as scott.emp, who has a hierarchy of level 4), then you do not have ot post sample data, just the results and explanations.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum {message identifier: = 9360002}If your hierarchy consists only of 2 levels, then a self-join will be probably more effective, simpler code and easier to maintain.
If you don't know how many levels in the hierarchy, then self-join is not an option. Use CONNECT BY or, if you have Oracle 11.2, a WITH recursive clause.
If you have a fixed number of levels (or an upper limit) greater than 2, then CONNECT BY (or a WITH recursive clause) will probably be the best.
-
Hi guys, I'm confused.
I was always told that one table can have ONLY 1 primary key. is this true or false? Or a table can cause several primary keys?
Second question is, if I join two tables that are formed as a result of columns.
Table 1:
Account_number
Account_create_month
Customer_address
Table 2:
Account_number
Account_create_month
Customer_phone
Should I join on account_number AND account_create_month? If yes why? and why not? Sorry if this is a stupid question. I'm just very confused. Thank youHello
Z KHAN wrote:
Hi guys, I'm confused.I was always told that one table can have ONLY 1 primary key. is this true or false? Or a table can cause several primary keys?
A table can have 1 primary key. There may be any number of columns (1, 2, 3 or more) in the primary key.
A table can contain any number of unique keys.Second question is, if I join two tables that are formed as a result of columns.
Table 1:
Account_number
Account_create_month
Customer_addressTable 2:
Account_number
Account_create_month
Customer_phoneShould I join on account_number AND account_create_month? If yes why? and why not? Sorry if this is a stupid question. I'm just very confused. Thank you
No, you do not have to connect using the two. If you use the two in a join given or not depends on what the data means, and what results you want.
-
Hello
I'm new to sql, and I am confused on how to write the columns attached on the self-join
for example:
Select emp.last_name, emp.hire_date, mgr.last_name, mgr.hire_date
employees emp
Join
Bishop used
on (emp.employee_id = mgr.manager_id)---(1) - vs-(2) - on (mgr.employee_id = emp.manager_id)
where emp.hire_date < mgr.hire_date
I use the employees on hr diagram table
Thank you!
Hello
It should be the 2nd condition on (mgr.employee_id = emp.manager_id)
Look at it like this
If the table Manager is a different table, then FK will be EMP (MANAGER_ID) to MGR (PK) and the State should follow the same rule if it were a self-join
Concerning
Salim
-
Hello
Here's 2 queries. First one help for the joints and the second query uses a join ancient. The first works very well and I tried to write the 2nd one to work exactly like the first. I don't know where to put the sub condition sysdate in 2nd query such that there operator.
AND trunc(SYSDATE) BETWEEN hapf.effective_start_date(+) AND hapf.effective_end_date(+)
1.
SELECT papf.full_name, hapf.name position_name FROM per_people_x papf, per_assignments_x pax, hr_all_positions_f hapf WHERE papf.person_id = pax.person_id AND pax.position_id = hapf.position_id(+) AND trunc(SYSDATE) BETWEEN hapf.effective_start_date(+) AND hapf.effective_end_date(+)
2.
SELECT papf.full_name, hapf.name position_name FROM per_people_x papf, per_assignments_x pax LEFT JOIN hr_all_positions_f hapf ON (pax.position_id = hapf.position_id) WHERE papf.person_id = pax.person_id
Any suggestion is appreciated.
Thank you
KK
SELECT papf.full_name,
hapf. Name position_name
THE women's wear per_people_x
JOIN THE
Pax per_assignments_x
ON)
PAPF.person_id = pax.person_id
)
LEFT JOIN
hr_all_positions_f hapf
ON)
Pax.POSITION_ID = hapf.position_id
AND
trunc (sysdate) BETWEEN hapf.effective_start_date AND hapf.effective_end_date
)
/
SY.
-
I have two tables joined via a pk/fk relationship. The main table has a field that indicates if a person entered the House (that's a request for home detention for minors) and to the left, or if it is still in the House.
1 = entered and left, 0 = always in the House.
The two tables are related through three fields (ID of the person, House ID, date of entry in the House)
I need a query to retrieve the records that exist in table 1 (the master) but do not exist in table 2 (retail) for (young) people who are STILL in the House. I need the query to run on the House n ° 2.
I tried a number of relationships to join, but none has been successful.
Any ideas on how to write this request will be appreciated.The next time after table descriptions...
I think you're asking something like that:
select pt.* from parent_table pt where pt.field = 0 and pt.home = 2 and not exists (select 'a child row for this parent row' from child_table ct where ct.person = pt.person and ct.home = pt.home and ct.entry_date = pt.entry_date);
-
I have assignment for sql query by asking list all products where the product designer living in the same region as the supplier of the product. However, I have no idea to solve it. Please help.
Here are the 4 tables I created:
CREATE table REGION
(
RegCode Varchar2 (8).
RegName Varchar2 (40),
Number of ShipDays (2),
KEY elementary SCHOOL (RegCode)
);
CREATE table SUPPLIER
(
Number of SuppCode (3),
SuppName Varchar2 (50).
Rating of Varchar2 (1).
RegCode Varchar2 (8).
PRIMARY KEY (SuppCode),
REGION (RegCode) FOREIGN KEY REFERENCES
);
CREATE table DESIGNER
(
FirstName Varchar2 (30),
Name Varchar2 (30),
E-mail Varchar2 (45).
Gender Varchar2 (1).
RegCode Varchar2 (8).
PRIMARY KEY (first name, family name)
REGION (RegCode) FOREIGN KEY REFERENCES
);
CREATE the PRODUCT table
(
ProdCode Varchar2 (3),
ProdName Varchar2 (35),
SellingPrice Varchar2 (4).
CostPrice Varchar2 (4).
FirstName Varchar2 (30),
Name Varchar2 (30),
Number of SuppCode (3),
PRIMARY KEY (ProdCode),
FOREIGN KEY (first name, family name) made REFERENCE to DESIGNER,
FOREIGN KEY (SuppCode) makes REFERENCE PROVIDER
);
Thanks a ton,
Mandy>
product designer d, p, s supplier, surely?
>Thanks for pointing it out.
I thought that OP change according to its standards, and they are just place holders.
Anyway, I will try to spend more time to give alias names better.
G.
-
Transform a table intelligently
Hi all
I have the following raw data (which are automatically uploaded to SAP) in my Oracle DB:
RAW_TABLE:
Notice Nr. Serial Nr. Question YES NO N.A. 304641403
P07567704094E Do you have an alarm at the time of the event? X 304641403 P07567704094E Was the patient on the device at the time of the event? X 304641403 P07567704094E Was he patient harm? X ?304641403 P07567704094E Was this one out of the failure of the box X 304641394 P0756768946B7 Do you have an alarm at the time of the event? X ?304641394 P0756768946B7 Was the patient on the device at the time of the event X 304641394 P0756768946B7 Was he patient harm? X 304641394 P0756768946B7 Was this one out of the box to fail? X This data doesn't pass (No.) ENR., series Nrs. appear 4 times for each question is shown in a row). To this effect, I'm changing this array in the following format:
FINAL_TABLE:
Notice Nr. Serial Nr. made a sound of alarm at the time of the event? Was the patient on the device at the time of the event? There was no harm patient? Was it a failure of the box off? 304641403 P07567704094E NO. Yes Yes NO. 304641394 P0756768946B7 N.A. NO. NO. NO. To be honest, I thought it was pretty easy, but now I am fighting with the little bit of PL/SQL knowledge that I possess.
How you guys would solve this problem step by step? Are you by chance a code example / ready model that transforms data like that? I'm happy for any suggestions I can get.
Thank you
Kevin
Hello
Here is an example of what I meant by using a table with all the expected questions:
The table could look like this:
CREATE TABLE question
(question_id NUMBER KEY primary SCHOOL (4)
, issue SINGLE VARCHAR2 (100)
);
INSERT INTO question (question_id, question) VALUES (1, "Has a SOUND ALARM at a TIME OF THE EVENT?");
INSERT INTO question (question_id, question) VALUES (2, "WAS THE PATIENT ON THE UNIT at THE TIME OF THE EVENT?");
INSERT INTO question (question_id, question) VALUES (5, 'WAS THERE ANY PATIENT HARM?');
INSERT INTO question (question_id, question) VALUES (13, "WAS THIS YEAR OF BOX FAILURE?");
You can have the other columns, if they are useful.
I noticed that your incoming data is not consistent on the capital or small letters, then normalize computer for this table.
To use this table, alter the query from the #3 like this answer:
WITH parboiled_data AS
(
SELECT r.notification_nr
r.serial_nr
q.question_id
CASE
WHEN r.yes_ IS NOT NULL THEN 'yes '.
WHEN r.no_ IS NOT NULL THEN 'no '.
WHEN r.na IS NOT NULL THEN 'N.A. '.
END AS years
Raw_table r
JOIN question q ON q.question = HIGH (r.question)
)
SELECT *.
OF parboiled_data
PIVOT (MIN (years))
TO question_id IN ( 1 AS alarm
2 UNDER in_unit
5 AS any_harm
13 AS out_of_box
)
)
ORDER BY notification_nr DESC
serial_nr
;
-
I am in the United Kingdom and have been sent a survey to join. However, when I get to the step to enter my IMEI, it won't let me join, because apparently my IMEI is in an "invalid format".
I checked several times, it is OK, and the necessary length. I have attached an image so this question. For security reasons, I've hidden in the middle of my IMEI.
What should I do? I really want to test the new software!
His 15 characters, because he says it should be. It is copied exactly from * #06 #, I'm sure it's correct!
EDIT: Misclicked the button 'best answer '. I have not yet found a solution!
-
I am a newbie to SQL and I studied the book of Fundamentals SQL Server Oracle OCA 12 c, but a section on natural joins to confuse me.
Basically, the author says:
SELECT r.region_name, d.department_name, l.city, c.country_name
DEPARTMENTS d
NATURAL JOIN places l, c countries, regions r;
The natural join between DEPARTMENTS and LOCATIONS creates a provisional result, consisting of 27 lines since they are implicitly attached on the column of location_id. This set is then Cartesian-joined to the table of the COUNTRY as a join condition is not implicitly or explicitly specified. 27 interim lines are attached to 25 lines in the COUNTRY table, which gives a new temp results set with 675 (27 × 25) rows and three columns: DEPARTMENT_NAME, CITY and COUNTRY_NAME. This set is then attached to the REGION table. Once more, a Cartesian join occurs because column REGION_ID is absent from any join condition. The final result set contains rows and four columns (675 × 4) 2700.
I can understand because you evaluate joins from the left. But then he wrote:
The JOIN... USE and JOIN... ON the syntaxes are better suited to join multiple tables. The following query joins four tables using the natural join syntax:
SELECT country_id region_id, c.country_name, l.city, d.department_name
DEPARTMENTS d
NATURAL JOIN places l
NATURAL JOIN country c
NATURAL JOIN region r;
This query generates correctly 27 lines in the final results set since the required join columns are listed in the SELECT clause. The following query illustrates how the JOIN... CLAUSE is used to extract the same 27 lines. A join condition can reference columns only in its scope. In the following example, the join of DEPARTMENTS slots can not reference columns in the COUNTRIES or REGIONS of tables, but the join between the COUNTRIES and REGIONS may refer to any column of four tables involved in the query.
This second method of the part of the natural writing joined confuses me. I don't understand the logic behind the 2nd series of States of Natural Join. For me, it seems that the first series and the 2nd set look alike, but they are apparently not.
Can someone tell me the differences?
Thank you!!
Hello
The more important thing to learn more about NATURAL JOIN is: never use it. If you add new columns, joins can get different results. I've never heard of someone uisng NATURAL JOIN apart from a manual or a question like yours.
There are a lot of things in Oracle that take the time to learn and are useful. All the time you spend learning things is better spent on them.
-
Hello
Oracle version: 11.1.0.7.0 - 64 bit
I read the documentation online at joins. The page is avialable here: joins at
My question is about the join order of evaluation of the conditions in clause and the conditions of those
are not the join conditions and are placed in the WHERE clause.
Consider the following pseudocode
SELECT
T1. Col1,
T2.Col1
Of
Table1 t1 LEFT OUTER JOIN table2 t2
WE
(condition_expression1)
WHERE
(condition_expression2)
Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article?
Thanks in advance,
Hello
dariyoosh wrote:
Hello
Oracle version: 11.1.0.7.0 - 64 bit
I read the documentation online at joins. The page is avialable here: joins at
My question is about the join order of evaluation of the conditions in clause and the conditions of those
are not the join conditions and are placed in the WHERE clause.
Consider the following pseudocode
SELECT
T1. Col1,
T2.Col1
Of
Table1 t1 LEFT OUTER JOIN table2 t2
WE
(condition_expression1)
WHERE
(condition_expression2)
Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article? ...
The reverse is actually closer to the truth, but we can't really make general statements like that.
SQL is not a language of the proceedings. Looking at the code SQL, we could say that the code does, but we cannot say much about how that code it. In other words, SQL is a language that describes the results you get, not the way to get them.
The optimizer will do everything what he thinks is faster if it does not change the results. If any order in which they are applied (in outer joins or CONNECT BY queries, for example), then think of the join is done first, and the value of the WHERE clause is applied to the result of the join.
Here is a query looks very much like you posted:
SELECT d.deptno
e.ename, e.sal
OF scott.dept d
LEFT OUTER JOIN scott.emp e ON e.deptno = d.deptno
WHERE e.sal > = 3000
ORDER BY d.deptno
;
Output:
DEPTNO ENAME SAL
---------- ---------- ----------
10 KING 5000
20 FORD 3000
20 3000 SCOTT
The scott.dept table contains deptnos 30 and 40; Why are they not in the result set? The query behaves as if the outer join is made first (production 15 rows), then the WHERE clause has been applied. All lines with deptno = 30 had sals down han 3000 and all single line with deptno = 40 was NULL in the sal column, then these lines are excluded (as well as other lines of deptnos 10 and 20), and only 3 lines above are left.
-
First, I'm joining the forum with a question CS4 and CS5 Suite for Mac. Can someone tell me why it is NOT a place to submit a question as it is here?
Creative Suites Mac forum seems to be closed, so moved that Creative Suites Windows the Forum of Creative Suites "base".
Then... Post your question and someone may be able to help... is your question about the installation of the old software on a new Mac?
IF El Capitan Mac read below
CS6 and previous programs have not been tested and will not be updated to run on Mac El Capitan
-which means you are trying to use CS6 and earlier at YOUR risk of having problems
-You can get CS6 and previous programs to install and run, or you can not (some do, some don't)
-IF not, Details of the message from the error messages and a person may be able to help (just not Adobe)
This information is a MUST to install old programs on Mac El Capitan
-You can't get the same error message, but here are some links that CAN help with old programs
-Java https://helpx.adobe.com/dreamweaver/kb/dreamweaver-java-se-6-runtime.html can help
Install CS5 on Mac 10.11 https://forums.adobe.com/thread/2003455 can help (also for others than CS5)
-also a TEMPORARY security change https://forums.adobe.com/thread/2039319
-the guardian https://support.apple.com/en-au/HT202491
-
I have been using LR for at least 4 years now and have continually updated. Current version LR6. I now want to join CC and thus access the PS and all the great stuff. Question: Can I get a refund or the recognition of the fact that I bought LR? Your answer please. PS - no doubt a question you get more often. !@
Hi Philippe,.
Please see: pricing and membership creative cloud plans | Adobe Creative Cloud
Otherwise, you can join Adobe sales for rate applications.
Kind regards
Sheena
-
Application of self-join interview question?
Hi guys!
I asked this question in an interview for the job as a developer of database.
I received a select based on symbol table and asked to drow the printout and then explain works step by step this statement.
Here are the instructions create & insert
/**********************************************/
create table tbl (number x, y varchar2 (50));
INSERT INTO tbl (x, y) VALUES ('A', 0);
INSERT INTO tbl (x, y) VALUES (1, 'B');
COMMIT;
/***********************************************/
Below the query (select statement)
SELECT tbl1.x
OF tbl tbl1 tbl2 tbl
WHERE tbl1.x = 0 OR tbl2.x = 1;
Please explain me the output and work step by step this statement...
Thank you...
Hello usman_noshahi,
If you omit the where the query clause will result as below
SELECT tbl1.x, tbl2.x
OF tbl tbl1 tbl2 tbl
/
X X
----- ----------
0 0
0 1
1 0
1 1
Request granted will result as below based on where condition on each line on top 4 rows... Or Condition will be returs real if one condition is met with the data set.
SQL > SELECT tbl1.x, tbl2.x
2 tbl tbl1 tbl2 tbl
3. WHERE tbl1.x = 0 tbl2.x = 1 GOLD
4.
X X
---------- ----------
0 0
0 1
1 1
SQL >
You can get the information in a different way as below...
SQL > explain plan set statement_id = "ORACLEFORUMS" for
2. SELECT tbl1.x
3 tbl tbl1 tbl2 tbl
4 WHERE tbl1.x = 0 OR tbl2.x = 1;
He explained.
SQL > select LPad (' ', 2 *(Level-1)). Level | '.' || NVL (position 0). ' ' ||
Operation 2. ' ' || Options of | ' ' || Object_name | ' ' || Object_type
3 || ' ' || Decode (id, 0, Statement_Id |) "Cost = ' | Position) | cost
4 || ' ' || Object_Node "Query Plan.
plan_table 5
6 start with id = 0 and statement_id = 'ORACLEFORUMS. '
7. connect by prior id = parent_id
8 and statement_id = 'ORAFAQ.
9 /
Query plan
--------------------------------------------------
1.7 STATEMENT SELECT ORACLEFORUMS cost = 77
2.1 NESTED LOOPS 7
3.1 ACCESS FULL TBL TABLE 3 TABLE
3.2 TABLE ACCESS FULL TBL TABLE 2
SQL > SELECT *.
TABLE 2 (DBMS_XPLAN. DISPLAY ('PLAN_TABLE', 'ORACLEFORUMS', 'BASIC'));
PLAN_TABLE_OUTPUT
------------------
Hash value of plan: 1718268327
-----------------------------------
| ID | Operation | Name |
-----------------------------------
| 0 | SELECT STATEMENT | |
| 1. NESTED LOOPS | |
| 2. TABLE ACCESS FULL | TBL |
| 5: TABLE ACCESS FULL | TBL |
-----------------------------------
10 selected lines.
SQL >
SQL > select LPAD (' ', 2 *(LEVEL-1)). operation 'OPERATION', 'options ',.
2 DECODE (TO_CHAR (id), '0',' COST = ' |) NVL (to_char (position), n / 'a').
3 object_name) 'OBJECTNAME', id | » -'|| NVL (parent_id, 0) | » -'||
4 NVL (position 0), 'ORDER', SUBSTR (optimizer, 1, 6) 'OPT '.
plan_table 5
6. start with id = 0
7 and statement_id = 'ORACLEFORUMS. '
8 connect by prior id = parent_id
9 and statement_id = 'ORACLEFORUMS. '
10.
OPTIO OBJECTNAME OPT OPERATION ORDER
------------------------- ----- ----------------------------------------------- ---------- ---------------
COST OF THE SELECT = 7 0-0-7 ALL_RO
NESTED LOOPS 1-0-1
TABLE ACCESS FULL TBL 2-1-1
TABLE 3-1-2 TBL FULL ACCESS
SQL >
ID ID-PARENT as follows...
00
10
21
31
Here level 1 has 2 childs (2,3)
Thus the sequential order of enforcement will be 2,3,1.
For more reference I recommend you read below, of course it's Oracle V8 but it gives more information.
Good reading!
Maybe you are looking for
-
Thunderbird can be transformed into a mass mailing good software by having the possibility of allowing a txt file name in the field "to". The software then picks up each email address in the txt file and sends the email to each email address individu
-
Hi - Thanks for your help in advance! I run an early 2009 24-inch 2.66 ghz, 4 GB, 640 GB. I run El Capitan (iMac1). This machine runs at capacity (nearly 600 GB 640 GB used). It has 120 GB of pictures (initially used Aperture but too complicated for
-
I have a photosmart c6280. I got it since early September. I am very very disappointed with it. the image quality is terrible. with the setting up, it's even worse when it is set to automatic. the prints are very washed-out, with spots on them.
-
B3P19A: composition of ink
I would like to know the composition of the ink in the produts B3P19A / B3P20A / B3P21A / B3P22A / B3P23A / B3P24A page because: http://h10010.www1.HP.com/wwpc/AA/en/Ho/WF17a/A1-12771-64199-69422-69422-5338287.html?DNR=2 have severed all ties. All I
-
Vista compatibility with epson stylus cx4600
I need to make my Vista compatible with epson stylus cx4600. I am over 50 years old, so things like computer start menopause lol. Help, please.