A subquery with case returning 2 columns
HelloI try a query in the format below.
SELECT x, y, z
FROM (SELECT Case when a
then, y1, z1
When b
then, y2, z2
END as y, z)
Can someone tell me the correct way to do it?
Thanks in advance :)
Use two case statements. One for each column:
SELECT x
, y
, z
FROM
( SELECT CASE WHEN a THEN y1 WHEN b THEN y2 END AS y
, CASE WHEN a THEN z1 WHEN b THEN z2 END AS z
from some_table
)
Published by: Sentinel December 12, 2008 11:23
Tags: Database
Similar Questions
-
Remove the statement with subquery with more than 1 columns
Hi all
I want to delete the data in the kpi_logs table for which the kpi_def_id column is less than the max (timestamp). The timestamp is the date data type. I wrote below query but its throwing an error as an SQL error: ORA-00936: lack of expression.
DELETE FROM KPI_LOGS WHERE (Select MAX (TIMESTAMP), KPI_DEF_ID of the KPI_DEF_ID KPI_LOGS GROUP);
Hello
user12251389 wrote:
I want to delete the data in the kpi_logs table for which the kpi_def_id column is less than the max (timestamp). The timestamp is the date data type. I wrote below query but its throwing an error as an SQL error: ORA-00936: lack of expression.
DELETE FROM KPI_LOGS WHERE (Select MAX (TIMESTAMP), KPI_DEF_ID of the KPI_DEF_ID KPI_LOGS GROUP);
Whenever you have a question, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the accurate results you want from this data, so that people who want to help you can recreate the problem and test their ideas.
If you ask about a DML operation, such as DELETE, and INSERT statements, you post should show what looks like the tables before the DML, and the results will be the content of the table changed after the DML.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum:
You want to keep only the maximum timestamp for the entire table, or you want the maximum timestamp for each distinct value of kpi_def_id?
If it is just the maximum timestamp for the whole picture, then
DELETE FROM kpi_logs
WHERE the timestamp<>
SELECT MAX (timestamp)
OF kpi_logs
);
If you want to keep the maximum timestamp for each individual value phew kpi_def_id, then:
DELETE FROM kpi_logs
WHERE (kpi_def_id, timestamp NOT IN)
SELECT kpi_def_id
MAX (timestamp)
OF kpi_logs
GROUP BY kpi_def_id
);
assuming that no column can be NULL.
Moreover, the TIMESTAMP is a data type, similar to this DAY. You'll only cause confusion by saying it is a type of data when it is really another. In addition, TIMESTAMP is a keyword from Oracle, is not a very good column name. Why not give your column a name more meaningful, accurate, such as create_date or entry_dt?
-
Problem of matrix report with model RTF - text columns
I have problem with matrix necessary report...
I did it before using the pivot function in rtf export then the stylesheet xsl fo... model
My problem here is in this case, the desired column (value - the center column) is the text column, and the pivot is based on the aggregate (sum or count) function that I don't want in my case.
Attached my XML, and sample to in the excel sheet...
and to understand the business, it's for quality module in EBS... The user can take 3 samples in the same sample for the same item, I want to show the name of tests alongside its results grouped by the number of the sample.
any help would be much appreciated...
This can be achieved through custom PivotTable.
I created the RTF template for your condition.
PFA (model and output)
-
SELECT which returns the columns as DESCRIBED?
Hello
I need a SQL that returns the column name and type as DESCRIBED in SQL * more.
I know that I can query all_tab_columns, but then I concatenate the string type myself.
SELECT column_name "Name" ,CASE WHEN data_type IN ('VARCHAR2','CHAR') THEN data_type||'('||data_length||')' WHEN data_type = 'FLOAT' THEN data_type||'('||data_precision||')' WHEN data_type = 'NUMBER' THEN CASE WHEN data_precision IS NULL THEN data_type WHEN data_scale = 0 THEN data_type||'('||data_precision||')' ELSE data_type||'('||data_precision||','||data_scale||')' END ELSE data_type END "Type" FROM all_tab_columns WHERE table_name = 'ABC' ORDER BY column_id;
An idea for another solution that considers each default data type?
Concerning
Marcus
Tip: you can run a trace and see what SQL query rained questions on your account when you issue a describe statement.
That said, I do not know if all the of that formatting is in the request or if it is made by the executable SQL more himself.
-
DML with values returned of dml another inside the WITH clause
Hello community, I want to use the ELECTION of an insert or update values to other insertion within a single transaction without staging of values returned. Here's what I mean. In some other dbs, I can do it like this
WITH moved_rows AS)
DELETE FROM products
"WHERE purchased_date > = ' 2010-10-01' AND purchased_date < ' 2010-11-01"
RETURN *.
)
INSERT INTO products_log
SELECT product_id, product_date, sysdate, user moved_rows;
I know the return value must be assigned to a local variable before they can be used within other dml, but I'm curious to know if the approach described above is supported in Oracle. Note that outside dml returns all columns (*) of the table products and then I took and chose the values I want to be inserted in the log table.
Hello community, I want to use the ELECTION of an insert or update values to other insertion within a single transaction without staging of values returned. Here's what I mean. In some other dbs, I can do it like this
WITH moved_rows AS)
DELETE FROM products
WHERE purchased_date > = "2010-10-01' AND purchased_date<>
RETURN *.
)
INSERT INTO products_log
SELECT product_id, product_date, sysdate, user moved_rows;
I know the return value must be assigned to a local variable before they can be used within other dml, but I'm curious to know if the approach described above is supported in Oracle. Note that outside dml returns all columns (*) of the table products and then I took and chose the values I want to be inserted in the log table.
Non - "approach above" don't is NOT supported in Oracle.
For operations from multiple tables, you must use SET of treatment to prevent other sessions modify data during your transaction.
Jarkko #8 post shows the steps involved.
-
Until the latest update when the url I wanted in the address bar of AutoComplete has been selected, it "accompanies" no more further by clicking on. I must now click the refresh arrow. It won't work even with the return. How can I operate the old way easier?
You can disable this extension in tools > Modules > Extensions and close and restart Firefox normally.
-
Advanced search and replace. How to replace the space with carriage return?
10.9.13.0/24, 10.9.4.2/32, 10.9.4.3/32 in
10.9.13.0/24
10.9.4.2/32
10.9.4.3/32Find replace them ',' with carriage return.
I still find articles on an advanced search and replace, but I can't seem to locate it.
OS X El Capitan 10.11.3
3.6.1 the numbers
HI Brendan,
You don't need an advanced find and replace for it.
In the search box, press, then space.
In the box replace by, press option-return.
Then click Find and replace and find until you are finished.
Kind regards
Barry
-
I try and install the SK and it fails for Web and ISO Setup > DVD drive. Same error every time:
12:22:50 Wednesday, July 11, 2012: C:\Program Files\Microsoft SDKs\Windows\v7.1\Setup\SFX\vcredist_x64.exe install failed with return code 5100
The following lines are less useful because they suggest to go to a place that I did not.
12:23:21 Wednesday, July 11, 2012: [SDKSetup:Error] Config_Products_Install: product Installation Microsoft Windows SDK for Windows 7 (failure): Please refer to Samples\Setup\HTML\ConfigDetails.htm document for more information. Fireplace: In SDKSetup.Product.ConfigureRelatedSfx () at SDKSetup.Product.ConfigureNewProduct (ManualResetEvent CancelEvent)
12:23:21 Wednesday, July 11, 2012: [SDKSetup] Config_Products_InstallNew: complete the installation of the new product: Microsoft Windows SDK for Windows 7
12:23:21 Wednesday, July 11, 2012: [SDKSetup:Error] Config_Products_Install: software Windows (failed) SDK installation: Installation of the product 'Microsoft Windows SDK for Windows 7' reported the following error: Please refer to Samples\Setup\HTML\ConfigDetails.htm document for more information. Fireplace: SDKSetup.Product.ConfigureNewProduct (ManualResetEvent CancelEvent) at SDKSetup.Product.SetupProduct (TaskMode taskMode, ManualResetEvent CancelEvent) at SDKSetup.ProductCollection.SetupProducts (TaskMode taskMode, believing believing, ManualResetEvent cancelEvent) to the SDKSetup.ConfigProducts.DoCurrentTask (Group TaskMode)Any ideas what could be worng? The rest of the log file is too big for this message but I can send it to someone who can help.
Hello
I suggest you try the steps listed from the link below,
Windows SDK fails to install with the return Code 5100
-
BlackBerry Smartphones BlackBerry Mini keyboard with case Convertible UK
Anyoine know when the official BlackBerry Mini keyboard with case Convertible, will be available to buy online UK or even Amazon UK?
Thanks for any help.
Sorted
-
Tables compressed with more than 255 columns
Hello
Anyone for a sql to find tables compressed with more than 255 columns.
Thank you
Jonu
SELECT table_name,
County (column_name)
Of utc user_tab_columns
WHERE utc.table_name IN (SELECT table_name
From user_tables
Compression WHERE = "ENABLED")
HAVING Count(column_name) 255 >
GROUP BY table_name
-
All,
I need assistance with data in clob column display dynamic content with any appropriate package but iam currently using htp.p, it seems to not work well. Some of my clob values are so big like length > = 18000 but when I use htp.p all the output text is collected without any line break, but I want to display the data IS STORED in the column to the table... any help is appreciated thank you.I think you can maximum diisplay 32 767 characters. You need to replace Chr (13) and Chr (10) with
in order to get it displays as you wish.Denes Kubicek
-------------------------------------------------------------------
http://deneskubicek.blogspot.com/
http://www.Apress.com/9781430235125
http://Apex.Oracle.com/pls/OTN/f?p=31517:1
http://www.Amazon.de/Oracle-Apex-XE-Praxis/DP/3826655494
------------------------------------------------------------------- -
Please give me help with case #0185011655
Please give me help with case #0185011655
This is a user to user, not the Adobe support forum
Adobe contact information - http://helpx.adobe.com/contact.html
-
I have asked to do a report, I
case ph.action_taken
When "V".
then... {the expression complex}
What I want is to say if ph.action_taken is T, V or Z - F
then make the expression complex without having to put in the complex expression
4 times. How to use an RC with case in SQL?
Thank youUse a different approach to the CASE and the IN operator. Like this:
with t as (select 'A' a from dual) select case when t.a in ('A','B','C') then 'OK' else 'Not OK' end b from t
-
How to fill in the right side of the shuttle with display/return values?
Hello
I know, the right way to fill in the right side of the shuttle's only:
It is comfortable for the user to see the name of the profile.declare v_list apex_application_global.vc_arr2; begin select profile_name return_value bulk collect into v_list from user_profiles where user_id = :p61_user_id; return (apex_util.table_to_string (v_list)); end;
However, I need a profile_id as return value, as I have on the left side of the shuttle.
The left side of the shuttle is filled with a selection list with display/return values, as you know.
I need both sides of the shuttle to return profile_id in order to create a merger.
How is it possible to fill the right side of the shuttle with display/return values?Make a selection list on the left side of the shuttle to return profile_name as return value as well.
In this way, the two parts of the shuttle will return the same value, which could be used as a State of fusion. -
How to create the table with the rows and columns using the layout?
One of my friends advised me to put my site on the mode of provision as it is better than the standard as he said
but I couldnot make an ordinary table with the rows and columns in mode available th
y at - there someone who can tell me how to?
Thank you very muchWednesday, April 18, 2007 21:01:38 + 0000 (UTC), "Mr.Ghost".
wrote: > A friend of mine advised me to put my whole site on the mode of disposal as its
> better than standard, as he saysYour friend won't. Don't listen to him any more. Mode of disposal creates
very fragile and rigid code pauses at the first opportunity.Gary
Maybe you are looking for
-
I always opened, 20 + tabs on Firefox and it is together to remember. However, when I open Firefox the first tab changes that I had opened it in my homepage, Google. I can use the thing "go back" to go to the page that I had there, but going back to
-
How to save a document to format rich text and images in PDF format manually?
How to save a document to format rich text and images in PDF format manually? Thank you!
-
Want 7640: 7640 Envy will not print black
OK, I've seen similar problems on the forum, but no answer doesn't solve my problem. The printer will copy in black, print a test page started from the printer, but will not print anything in black from the computer. The test of the generated printer
-
Pavilion g 6 series: malware
Hi my name is the. When I connect to some web sites, I noticed that the ads appear under site web I visit and sound according to ads now appear on my computer. It's just the normal bin that I treat, or is this a sign that some kind of malware has bee
-
Where is promised 10 Windows for my V3-371?
Register for Windows 10 booking on Microsoft website in July this year. Tell me Microsoft app - waiting, attentio ci. But for now, I see that my V3-371 in the list of models supported by Windows 10. And even see the list of W10 drivers for my laptop.