Case to interview several values and unique to different tables return value
Hi This is my first picture:with Table_1
as
(
select 'CAR' Object, 2000 Policy from dual
union all
select 'BIKE' Object, 2000 Policy from dual
union all
select 'HOUSE' Object, 2000 Policy from dual
union all
select 'MOBILE' Object, 2000 Policy from dual
union all
select 'MONEY' Object, 2000 Policy from dual
union all
select 'CREDIT' Object, 2000 Policy from dual
union all
select 'SCOOTER' Object, 2001 Policy from dual
union all
select 'BIKE' Object, 2001 Policy from dual
union all
select 'BEACH' Object, 2001 Policy from dual
union all
select 'HOUSE' Object, 2001 Policy from dual
union all
select 'MONEY' Object, 2001 Policy from dual
union all
select 'CREDIT' Object, 2001 Policy from dual
union all
select 'DOOR' Object, 2002 Policy from dual
union all
select 'BIKE' Object, 2002 Policy from dual
union all
select 'GARDEN' Object, 2002 Policy from dual
union all
select 'MOBILE' Object, 2002 Policy from dual
union all
select 'MONEY' Object, 2002 Policy from dual
union all
select 'CREDIT' Object, 2002 Policy from dual
)
select * from Table_1
I need to query the column object from table_1 for CAR or HOME and if they are present and then returns 'Y' otherwise 'n'. Linking this table_1 to table_2 through politics and the result will be table_3with Table_2
as
(
select '21' AGE, 2000 Policy from dual
union all
select '22' AGE, 2001 Policy from dual
union all
select '27' AGE, 2002 Policy from dual
)
select * from Table_2
with Table_3
as
(
select '21' AGE, 2000 Policy, 'Y' Many_Obj from dual
union all
select '22' AGE, 2001 Policy, 'Y' Many_Obj from dual
union all
select '27' AGE, 2002 Policy, 'N' Many_Obj from dual
)
select * from Table_3
Thanks in advanceBanner:
Oracle Database 11 g Release 11.2.0.2.0 - 64 bit Production
PL/SQL Release 11.2.0.2.0 - Production
"CORE 11.2.0.2.0 Production."
AMT for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
!
Thanks for the insert statements.
Here's a way
with Table_1
as
(
select 'CAR' Object, 2000 Policy from dual
union all
select 'BIKE' Object, 2000 Policy from dual
union all
select 'HOUSE' Object, 2000 Policy from dual
union all
select 'MOBILE' Object, 2000 Policy from dual
union all
select 'MONEY' Object, 2000 Policy from dual
union all
select 'CREDIT' Object, 2000 Policy from dual
union all
select 'SCOOTER' Object, 2001 Policy from dual
union all
select 'BIKE' Object, 2001 Policy from dual
union all
select 'BEACH' Object, 2001 Policy from dual
union all
select 'HOUSE' Object, 2001 Policy from dual
union all
select 'MONEY' Object, 2001 Policy from dual
union all
select 'CREDIT' Object, 2001 Policy from dual
union all
select 'DOOR' Object, 2002 Policy from dual
union all
select 'BIKE' Object, 2002 Policy from dual
union all
select 'GARDEN' Object, 2002 Policy from dual
union all
select 'MOBILE' Object, 2002 Policy from dual
union all
select 'MONEY' Object, 2002 Policy from dual
union all
select 'CREDIT' Object, 2002 Policy from dual
),
Table_2
as
(
select '21' AGE, 2000 Policy from dual
union all
select '22' AGE, 2001 Policy from dual
union all
select '27' AGE, 2002 Policy from dual
)
SELECT
age,
policy,
Many_Obj
from
(
SELECT
t2.age,
t2.policy,
CASE
WHEN SUM(
CASE
WHEN t1.object IN ('CAR','HOUSE')
THEN 1
ELSE 0
END) over( PARTITION BY t2.age,t2.policy) > 0
THEN 'Y'
ELSE 'N'
END Many_Obj,
row_number() over (PARTITION BY t2.age,t2.policy order by 1) rn
FROM
Table_1 t1,
Table_2 t2
WHERE
t1.policy = t2.policy
)
where rn = 1;
AGE POLICY MANY_OBJ
--- ---------------------- --------
21 2000 Y
22 2001 Y
27 2002 N
I advise you to spend the time learning analytical questions and using CASE expressions.
Tags: Database
Similar Questions
-
Firefox crashes because as his tent to update the last website I went to have uninstalled and reinstalled several times and always the case. How can I erase this site so it seems not for her? Also happens in safe mode.
Follow the suggestions mentioned in the following article:
- Get help to solve this Crash
- Answer with your Crash IDs
-
Difference between the plan of photography and unique app
Hello team,
I want to choose between one of the plans - photography plan and Plan App unique
I'm from the India. I have a few questions and doubts about plans, I want the concern team to meet each of my straightened queries. It will be much appreciated.
Plan of photography, I see that for 2 Applications, CC of Photoshop and Lightroom CC price is Rs. 499 /-per month (paid annually). Whereas if I choose only one App pland and select software is Photoshop in this case, the price is Rs. 1000 /-per month (paid annually)
It's a bit confusing to me. For only Rs. 499 /-I get both apps and Rs. 1000 /-I get one App. Why so.
Are there other differences, that I can't know. Can anyone please suggest me the complete list of the differences between these two plans, which is not included in this link - pricing and membership creative cloud plans | Adobe Creative Cloud
And
2. If I want to choose the plan of photography that is currently showing Rs. 499 /-per month. And if I want to unsubscribe or stop after 2 months, then do I have to pay fees for 2 months only or for the entire year or 50% of the total price of the year.
3. Similarly, if I have to stop after 7 months, then I will have to pay the price for 7 months (7 x 499 = 3493) or for the entire year.
4. Finally, do I have the possibility, to cancel the subscription at anytime in between, say for everything after 2 or 7 months or more.
5. I will be able to continue software also offline by downloading them to my computer or laptop or simply by connecting online. Can I use the application on my mobile too with the plan of photography. I mean is there any mobile application also who will be given free to use after you have purchased the plan of photography.
6. can I download and install apps on several desktop and laptops also. Or at least a desktop and a laptop.
7. will I get free CC of Photoshop and Lightroom CC updates after purchase of photography for a year and free plan.
8 will. what kind of support I once I bought the plan of photography. I get telephone, chat and support the type of ticket or email support or one of these.
Your kind positive response is significant.
Concerning
Anish-desloge wrote:
It's a bit confusing to me. For only Rs. 499 /-I get both apps and Rs. 1000 /-I get one App. Why so.
Are there other differences, that I can't know. Can anyone suggest me please the complete list of the differences between these two systems
See the differences between Photoshop and creative photography Cloud programs
Photoshop photography program mentioned in the article was an older plan which is no longer available. It has been replaced by Cloud creative photography program.
-
Sql statement variable gives several values
Hello
I have a variable that has sql statement and it gives several values and I want to use this variable in one of the filter of interface condition to filter the data in the source table (which has millions of records).
some could let me know the best method to achieve this scenario.
Appreciate your help.You are right. Yesterday, I don't think in this case where the data could be from a different server. But I completely forgot today.
Ok. Here you can find how to use sys_connect_by_pathhttp://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:907278700346567560
Be careful with the size because I think that there is a limit to what can contain the variable ODI.
After you have assessed the variable is how it could be used in the filter
ITEM_TYPE_ID IN (#var_csv_id_list)
-
Primary key and unique key not Null
Hello gurus,
Asked in an interview about the difference between primary and unique keys.
I talked Unique keys can accept null values, but they are unique through should have the table. So, the next question asked me was "a Unique key NOT NULL can be treated as the primary key?
Tricky question! :)
I said yes! that it meets the requirement to be a primary key for this particular table, but since this isn't really a primary key, that it can't be covered in the foreign keys.
The interviewer wanted just a Yes or no.
Can someone please put some of this?
Thanks in advance!Two things.
1. unique can also be referenced as a foreign key. If your statement "but because this isn't really a primary key may not be seized key foreign." is not true.
2. primary key and Unique key are different (for example you can have more than one UK in a table but PK's alone) and to know the difference, read some RDBMS concepts.I'm curious to know what is the outcome of your interview? ;)
-
[8i] need to combine several values in a column
I work in 8i...
I have data as follows:
The results that I want are:CREATE TABLE item_year ( item_no CHAR(25) , year CHAR(4) ); INSERT INTO item_year VALUES ('item1','1998'); INSERT INTO item_year VALUES ('item1','2002'); INSERT INTO item_year VALUES ('item1','2003'); INSERT INTO item_year VALUES ('item1','2004'); INSERT INTO item_year VALUES ('item2','1984'); INSERT INTO item_year VALUES ('item2','1991'); INSERT INTO item_year VALUES ('item2','2006'); INSERT INTO item_year VALUES ('item2','2008'); INSERT INTO item_year VALUES ('item2','2010');
My inclination is to rotate the results, but my problem is, I don't know how many years will see room for a particular item. In theory, it could it upwards in each year between any point in the past through the current year. In practice, the year is 1997, and I can't think of any situation where an older date occur in the future, because this table is a table of history. Thus, at the present time, the years, I would need to look to be 1997-2010, but of course, would come January, it will be 1997-2011, etc.. So either way is for me to do without having to create a procedure or something?ITEM_NO YEARS ------------------------------ item1 1998, 2002, 2003, 2004 item2 1984, 1991, 2006, 2008, 2010
Hello
You can do the slightly simpler query by losing the CONNECT BY. In the example that you copied, CONNECT BY was the only way to get the items that should be grouped together. In your case, a simple query will do:
SELECT item_no , CAST ( MULTISET ( SELECT year FROM item_year WHERE item_no = all_item_nos.item_no ORDER BY year ) AS myArrayType ) AS years FROM ( SELECT DISTINCT item_no FROM item_year ) all_item_nos ;
I don't know how to get a simple string (rather than myArrayType) for results without the help of PL/SQL.
If you use the PL/SQL, you might consider this approach: write a function that takes an id (like item_no) as an argument and returns a string (the list or results). You probably want several similar functions for the different arguments, tables and columns. If Yes, you can isolate the part that actually built the chain to verify that the results are actually in the allocated space, in a generic function (such as concat_query, below) and to call this generic function to a specific function (such as all_years, below) adapted to a specific situation.
This is a package that contains the generic function:CREATE OR REPLACE PACKAGE string_agg AS TYPE concat_query_cursor_type IS REF CURSOR RETURN dual%ROWTYPE; FUNCTION concat_query ( in_cursor IN concat_query_cursor_type, in_separator_txt IN VARCHAR2 ) RETURN VARCHAR2 ; END string_agg; / SHOW ERRORS CREATE OR REPLACE PACKAGE BODY string_agg AS FUNCTION concat_query ( in_cursor IN concat_query_cursor_type, in_separator_txt IN VARCHAR2 ) RETURN VARCHAR2 IS c_txt VARCHAR2 (4000); return_txt VARCHAR2 (4000) := ''; return_max_val INTEGER := 4000; -- declared size of return_txt row_cnt INTEGER := 0; -- number of pa records found so far BEGIN LOOP FETCH in_cursor INTO c_txt; EXIT WHEN in_cursor%NOTFOUND; IF row_cnt > 0 THEN c_txt := in_separator_txt || c_txt; END IF; IF LENGTH (return_txt) + LENGTH (c_txt) > return_max_val THEN c_txt := SUBSTR ( c_txt, 1, return_max_val - LENGTH (return_txt) ); END IF; return_txt := return_txt || c_txt; IF LENGTH (return_txt) >= return_max_val THEN EXIT; END IF; row_cnt := row_cnt + 1; END LOOP; CLOSE in_cursor; RETURN (return_txt); END concat_query ; END string_agg; / SHOW ERRORS
Here is an example of a specific function using this package:
CREATE OR REPLACE FUNCTION all_years ( in_item_no IN item_year.item_no%TYPE ) RETURN VARCHAR2 IS q_cursor string_agg.concat_query_cursor_type; return_txt VARCHAR2 (4000); BEGIN OPEN q_cursor FOR SELECT year FROM item_year WHERE item_no = in_item_no ORDER BY year; return_txt := string_agg.concat_query ( q_cursor, ', ' ); RETURN (return_txt); END all_years; / SHOW ERRORS
The all_years above is a stand-alone function. You could also just have a function in a package, or string_agg, or another package, if that suits your needs.
As you can see, the specific function is quite trivial. You could probably do something with dyanamic SQL, where you write another function, with the text of a query as a string argument, and it calls concat_query and returns this value.Here is an example of using the all_years function in a query:
SELECT item_no , all_years (item_no) AS years FROM ( SELECT DISTINCT item_no FROM item_year ) ;
You could SELECT DISTINCT in the main query, but it would be less effective.
Output:ITEM_NO YEARS ------------------------- ---------------------------------------- item1 1998, 2002, 2003, 2004 item2 1984, 1991, 2006, 2008, 2010
-
my account has been hacked several times and sends mail spam to the people on my list
my account has been hacked several times and is to send spam to people on my list. I changed my password several times and it continues to happen. I took everyone off my email list with the exception of an e-mail address that I created to alertme in the case of this kind of thing happens, it works. I pay for this msn messaging service and I'm upset that anyone can hack my email so easily. I want that stopped.
It is up to you to use Kaspersky Rescue Disk 10 to remove any malware. The hot spare is a bootable Linux distribution that will search for and remove malicious software that can hide when the HD is active.
Booting from the rescue disk will ensure the HD is not Active -Kaspersky Rescue Disk 10Once the system is cleaned up, contact MSN and ask another reset of password.
Expert MowGreen Windows IT Pro - consumer safety
-
I would be grateful with the help of an EXPERT. I would be very grateful if you can help me.
DEFENDER lights. He tells me it's off and it must be enabled. I tried several times and I can't activate it. I see the DEFENDER icon (it looks like gray Castle) in my field of security. The ICON in my programs (install/remove) is NOT there? 0x80071A90 error message
98CB24AD-52FB-DB5F-A-15-C8B3B9AIE18EIn ADDITION, 2nd edition: I have an infected memory stick digital camera. It has infected my computer 4 times from AUGUST 2009 I realized that it was the culprit. It leads to the DEATH of SCREEN BULE. He arrived Friday. I made the recovery of the system. I REINSTALLED it. QUESTIONS: What should I do with this memory stick? Throw it in the trash? I lost 6 months of precious photos. Can I move photos or keep the photos? What do you recommend?
In ADDITION, through the memory stick infect my computer and then the PICTURES who made the infection. About 3 or 4 flash drives have been put in my computer. Are they all infected? I have College CRITICISM of work on one that I can't lose. What should I do? Should these flash drives be CLEANED of INFECTION? They CLEAN themselves without losing me my files stored? What do you recommend? I need someone to assess whether or not they are infected?
The infected memory stick infects my digital camera? And my Photosmart HP ALL IN ONE printer? Are they ALSO infected? Will be going to infect my computer.
I do not think that the SECURITY SOFTWARE I have: (free from Comcast) Norton and Microsoft Security Essentials, are fighting the infection from the memory stick. It would be good to have an EXPERT evaluate the memory stick and tell me what they think. As well as my flash drives, an expert must evaluate and tell me if 3 flash drives are infected? And they are clean? And the files that I have on them can be saved?
I hope you can help me, THANK YOU, WG
First, you have to run two anti-virus programs. This is NOT recommended.
Second... you state one of them is Microsoft Security Essentials. If this is the case, you can't turn on Windows Defender because MSE already made defender and stops automatically Defender because it is no longer necessary.
Difficulty of these 2 things and your problem should be solved.
-
CC does not refresh on my Win7 machine. I tried several times and it closes after update download and try to install. Downloaded new application from Adobe, downloaded and tried to install received error 50. Help!
Hello
as strange as it may seem I'm afraid it is a challenge for Creative tool Adobe cleaning of cloud.
Sometimes - for some reason-CC "unwilling" work. In this case you should CC completely remove and reinstall by using Adobe Creative cloud cleaning tool. (A try to uninstall by own resources is not enough!)
I quote:... helps resolve installation problems for Adobe Creative Cloud and Adobe Creative Suite (CS3 - CS6) applications. The tool removes the records facility for preliminary facilities of Cloud applications or Creative Suite creative. It does not affect existing installations of earlier versions of Creative Suite or creative Cloud applications.
Please use: l http://helpx.adobe.com/creative-suite/kb/cs5-cleaner-tool-installation-problems.htm and follow the prescribed sequence of operations
Sometimes, the "opm.db" file is the culprit. In this case, you must remove it.
If necessary and for questions and so "open" Please use the cat, plus I had the best experiences.
Hans-Günter
-
How can I select several values for popup LOV
Hello
I need to select several values for popup lov. Is it possible to select several values from popup lov
Concerning
Veronica BCheck your page now, added a javascript in shared components file > images and a css in the components share > cascading style sheets
I used the plugin below
http://www.erichynds.com/jQuery/jQuery-UI-MultiSelect-Widget/ -
Combine several values of rank in a line like comma delimeted string
Hello
I have a requirement to combine several values of rank in a line as the comma delimeted string as below
INDEX_NAME COLUMN_NAME POSITION_COLONNE
EMP_EMAIL_UK EMAIL 1
EMP_EMP_ID_PK EMPLOYE_ID 1
EMP_DEPARTMENT_IX DEPARTMENT_ID 1
JOB_ID EMP_JOB_IX 1
EMP_MANAGER_IX MANAGER_ID 1
EMP_NAME_IX LAST_NAME 1
EMP_NAME_IX FIRST_NAME 2
I write in a SQL and the output I need is, for example EMP_NAME_IX LAST_NAME, FIRST_NAME.
I can't write any function as well.http://www.Oracle-base.com/articles/Misc/StringAggregationTechniques.php
SELECT index_name, ltrim(sys_Connect_by_path(column_name, ','), ',') column_names FROM (select index_name, column_name, row_number() over(partition by index_name order by column_position) rn from all_ind_columns WHERE table_owner = 'HR') WHERE connect_by_isleaf = 1 START WITH rn = 1 CONNECT BY PRIOR rn = rn - 1 and prior index_name = index_name
-
does an if test for several values
I want to test if a clip is on some frames; can I make sure that each is instruction for each of my two buttons test if the movieClup is on several frames something like this (but it works of course):
hyper_btn.onPress = function() {}
If (symptoms_mc._currentframe == 1, 4, 5, 9, 10, 11, 14, 15, 17, 18) {}
symptoms_mc.gotoAndStop (frameCounter + 1);
} else {}
verifyFinished2_mc.gotoAndStop ("incorrect");
}
};
hypo_btn.onPress = function() {}
If (symptoms_mc._currentframe == 2, 3, 6, 7, 8, 12, 13, 16, 19) {}
symptoms_mc.gotoAndStop (frameCounter + 1);
} else {}
verifyFinished2_mc.gotoAndStop ("incorrect");
}
};in the case of statements. is or and & is therefore
If (this == | == this Gisèle)
{
}You should consider using a switch statement for your goal however.
This is a refrence General javascript
http://msdn.Microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/scriptinga. ASP.
-
Extract the most several value in a TextArea of the Dummy Table
Hello
I have three point 1 selection list for the CODE OF MEDICINE and a 2nd is text field for MEDICINE BACK and 3rd P2_MED_COUNT to add new drugs and created a table with two columns of DUMMY_MEDICINE
MED_CODE, MED_DOS
I use a cursor to retrieve several value in the text box, but it shows enter only last value user. I want that enter all data by user
I created an insert statement on click Add more button medicinedeclare p varchar2(200); rec DUMMY_MED_LITS%ROWTYPE; cursor c1 is select * from DUMMY_MED_LITS; begin open c1; p:=0; :P2_MED_COUNT:=0; loop fetch c1 into rec; exit when c1%notfound; p:=rec.MED_CODE ||'-'||rec.MED_DOS|| CHR(13) || CHR(10); :P2_MED_COUNT:=p; end loop; close c1; end;
How can I retrieve data from Table in an element.begin insert into DUMMY_MED_LITS values(:P2_MEDICIN_NAME,:P2_MED_DOS); end;
How can I do that.
Thank you
Ed
Published by: Ed on April 3, 2010 12:31 AMHi Maury,
Change this line
p: = rec. MED_CODE | » -'|| recomm. MED_DOS | CHR (13) | CHR (10);
TO
p: = rec. MED_CODE | » -'|| recomm. MED_DOS | CHR (13) | CHR (10) * | p * ;In addition, to make the statement P2_MED_COUNT: = p; after the end of the loop...
Kind regards
Shijesh -
I allowed off all my computers several times and iTunes still shows that I have authorized 5. I can not re - allow one of my computers and cannot allow overall because I did last October. I tried a logout and back logging, remove the SC info folder etc... Any ideas?
I allowed off all my computers several times and iTunes still shows that I have authorized 5
Normally, you can only authorized computers off once a year.
-
Experienced a severe slowness and lock-up with Firefox to the end, which ends with a sharp decline in the use of memory and I have repeatedly shut down by the Task Manager. I created a new profile and disabled hardware acceleration. I tried to disable all plug-ins and extensions, but I noticed that sometimes (not always) plugin container was always an active process, I don't understand. Why would it be active when there is no plugin activated? I also noticed that when the plugin container is not active (list under process in the Task Manager), I don't have this problem and Firefox works normally? I need to block the plugin container. Help, please.
If you have deactivated plugins and plugin-container should not be executed. It's one of the reasons I suggested malware scans.
The Windows XP Task Manager lists the processes running. It will list the plugin - container.exe but I don't think it goes further. IIRC a Sysinternals utility was required to get information on the processes associated with the plugincontainer.
Microsoft will now offer free downloads and documentation for which is the Sysinternals software.
Maybe you are looking for
-
new time machine snapshots copied to the old directory of the machine not recognized
I had a time Capsule 2 TB which showered, and I started a new backup (a USB key) by mode Apple drive. It took me a while to return to deal with the old clichés left on my Time Capsule. I found nothing specific online to tell me how to deal with this,
-
When ever I start FF the screen is distorted - on a slope, in fact. The text on the web pages will be expanded vertically, blackout curtains. The radio buttons will be moved from its position, but if I am lucky and drag the mouse all over where it sh
-
Re: Satellite A500/026 get frozen and cannot close
Satellite A500/026, I bought a month before, and actually use days perhaps only 14 days. That books get frozen after 5 minutes and can't stop, no matter what you do.I made the recovery of factory default. the first can not finished and frozen in the
-
I can't print from my computer. This has happened with no other visible defects on the computer or the printer. When I use the printer in case of problem, and hit the 'add printer' link, I get the error message "print spooler service is not." "I did
-
Replacement of Srvany.exe
There has been several queries on replacement srvany.exe (or instsrv) executables, but nothing definitive (at least that I could find). Essentially, it seems that srvany.exe is a utility provided with Windows MS resource kit, but then never really s