Given multiple options to get filled by using the SQL query
I have the following data in the table.I want to fill the column custid with a few conditions.
(1) If a client is on a loan account as custid must get filled. (for example: 124)
(2) if the multiples are on a single loan account then
(a) if one of the clients has rolename = "w1" then it must be filled. (for example: 125)
(b) If several customers a rolename = "w1" then custid minimum should get populated(eg:123)
(c) If none of the clients has rolename = "w1" then custid minimum should get populated(eg:126)
LOANNO ROLENAME CUSTID
123 X 1
123 2 W1
123 3 W1
124 Y 4
5 125
125 6 W1
7 126
8 126
9 126
And my output looks like
LOANNO ROLENAME CUSTID
123 2 W1
124 Y 4
125 6 W1
7 126
I tried the departure from
SELECT ACCNO, ROLENAME, MIN (CUSTID)
FROM TABLENAME
ACCNO GROUP, ROLENAME
HAVING ROLENAME = "W1".
How to all conditions.
Could you please help in this?
I tried again on that.
Thanks in advance.
Concerning
KVB
Hello
I see now: you do not want the Group BY accno both rolename; that would produce a line of output for each combination separate accno / rolename. You want only one line of output for each separate accno.
One way to do that is a Query of Top - N , like this:
WITH got_r_num AS
(
SELECT accno, rolename, custid
, ROW_NUMBER () OVER ( PARTITION BY accno
ORDER BY CASE
WHEN rolename = 'W1'
THEN 1
ELSE 2
END
) AS r_num
FROM table1
)
SELECT accno, rolename, custid
FROM got_r_num
WHERE r_num = 1
;
You could do it with GROUP BY, but it's messy:
SELECT accno
, MIN (rolename) KEEP ( DENSE_RANK
FIRST
ORDER BY CASE
WHEN rolename = 'W1'
THEN 1
ELSE 2
END
, custid
) AS display_rolename
, MIN (custid) KEEP ( DENSE_RANK
FIRST
ORDER BY CASE
WHEN rolename = 'W1'
THEN 1
ELSE 2
END
) AS display_custid
FROM table1
GROUP BY accno
;
Tags: Database
Similar Questions
-
How to select only the part by using the sql query
Hello
I have the task to retrieve only the integral of the input text by using the sql query.
The entry is as follows
Entry for the price setting
$12.5 (FYI without space)
$ 12.5 (FYI single space)
$ 12.5 (double space FYI)
$12.5 (FYI multiple space)
$12.5 (FYI multiple space)
Output expected of 12.5
The price is the type varchar2 column in the store_price table.
Please let me know how to achieve this.
Thanks in advance.
If this is always the case that you get a $ followed by a number of places, you can use something like:
Select to_number (ltrim ('$ 12.5',' $')) DOUBLE
or
SELECT ltrim ('$ 12.5',' $') OF double
but take care of your nls_numeric_character settings if they are defined so that, for example, a comma is the decimal separator, you will have a problem.
HTH
-
Change the font color in a report by using the SQL query
Hello
I'm changing the font color based using a BOX the query in the form below:
I can get this working by selecting the Standard report column in the type of the column header . However this to say that I can't use the LOV LOV options involve removing the HTML characters.select "ORDER_ID", "ORDER_REFERENCE", "ORDER_DATE", "ORDER_SOURCE", "TOTAL_DISCOUNT", "DELIVERY_TYPE", "PICKUP_DATE", case when order_status = 1 then '<font color="red">'|| order_status||'</font>' else '<font color="blue">'||order_status||'</font>' end order_staus, "DELIVERY_STATUS", "USER_ID", "CUSTOMER_ID", "SITE_ID" from "ORDERS"
Is there a way I can conditionally change the font with the above query and use LOV as well? Thank you.
Environment
Apex 4.1.1 to apex.oracle.com
Theme 13
Published by: taepodong on June 3, 2012 07:28I'm sure that not looking the application form first before posting this question.
Your solution would be:
Please edit your report column under > report attributes > and select the property view as as a Standard report column -
Dependencies of object database by using the SQL query?
Hi guys,.
I just see the nice feature to discover the database object dependencies in the APEX (generator application-> app 123-> utilities-> database object dependencies).
Is there a way to get this dependencies just with a SQL query? Also should I calculate a process in order to get the current dependencies? In APEX, you press a calculate button before you can see the dependencies.
Thanks in advance and greetings from the Germany
Steven
After you import the app Builder application APEX 4500, I saw that the Start button the following process:
wwv_flow_theme_manager.find_object_dependencies (p_flow_id =>: fb_flow_id, p_page_id-online null);
In my example I can't use it, only the APEX_050000 user has privileges to use, and you must grant the privileges of your schema, so if you want to use it inside your application. My application must be independent of the schema and the specific database.
Also it is not recommended to use this procedure because it is one of the procedures not supported that are only used by oracle.
-
generations of months using the sql query
Hello
Based on the input of date parameter, I need display every month in the current year and last year.
For example, suppose that my setting date is December 5, 14 ', I need the output below.
JANUARY
FEBRUARY
MARCH
APRIL
MAY
JUNE
JULY
AUGUST
SEPTEMBER
OCTOBER
NOVEMBER
DECEMBER
JANUARY
FEBRUARY
MARCH
APRIL
PEUT
Until the month of May and the month last year. I came with the request. Please find the following query.
Select to_char (add_months (trunc(sysdate,'year'), level-1), 'MONTH') mth
of the double
connect by level < = 12
Union of all the
Select to_char (to_date (ddate, 'MM'), 'MONTH') month
(select 1 + rownum - 1 ddate
from user_objects
where (1 + rownum - 1) < = to_number (to_char (to_date ('12-05-14', ' dd-mm-yy'), 'mm')));
But I don't want to use the data user_objects dictionary. Can you please guide how to achieve this output, or can u give me some other request too if possible.
Thank you
Siva
Try the below
SELECT TO_CHAR (ADD_MONTHS (ADD_MONTHS (TRUNC (TO_DATE(:date1,'DD-MM-YY'), 'MM'),
((- MONTHS_BETWEEN (trunc (to_date(:date1,'DD-mm-YY'), 'MM'), trunc (to_date(:date1,'DD-mm-YY'), 'YY')) + 12)).
(LEVEL-1))
, 'MONTHS '.
'NLS_DATE_LANGUAGE = ENGLISH') FROM dual months_between
CONNECT BY LEVEL<=>=>
-
How to get the reconciliation AD event data using the SQL query.
Hi all
I was trying to get all the recon data to target AD Recon of IOM db, but it seems that at the OIM 11 g we have recon not given in the tables: UCR, CRE, etc.. Use tables "RECON_"... ', my question is all no bady has example query to extract data from recon tables?
The best
MPIt should be a matter of linking your reconciliation table of user AD (early RA_) with the RECON_EVENTS of RE_KEY table.
In my case, I have user OID reconciliation (so my RA_ table will be different to yours) and can use something like:
SELECT RECON_EVENTS. RE_STATUS, RECON_EVENTS RA_OIDUSER5.*, RA_OIDUSER5 WHERE RECON_EVENTS. RE_KEY = RA_OIDUSER5. RE_KEY;
Of course, then depends on what information you want to filter and recover.
-
Column of the row on a table (using the SQL query)
Data in my table looks like this.
Data in the table
===============
COL_1, COL_2
---------- ----------
1 ABCD
2 ABC
3 ABCDE
4 AB
5 ABCDEFGH
Now, he must, for the entire line, length COL_2 text exceeds 3, display the text remaining in the new line. For example, the first row (COL_1 = 1), COL_2 length is 4, so in SQL output two lines will be displayed as shown below. Also, the last row (COL_1 = 5), the length is 8, then, in SQL, output 3 lines will be displayed as below. And for the COL_1 = 2 & 4, only 1 rank will be displayed as the text COL_2 length is less than or equal to 3.
OUTPUT
===============
COL_1, COL_2
---------- ----------
1 ABC
1 D
2 ABC
ABC 3
3 DE
4 AB
5 ABC
5 DEF
5 GH
We need to implement using SQL only.
Hello
the solution of etbin uses recursive subquery factoring available on Oracle 11 g 2.
Since you have not mentioned your version I write here 2 alternatives using CONNECT BY and Xquery:
with mydata as
(
Select 1 c1, c2 'ABCD' Union double all the
Select 2, 'ABC' from dual union all
Select 3, 'ABCDE' from dual union all
Select option 4, "AB" dual union all
Select 5, "ABCDEFGH" of the double
)
Select c1, substr (c2, level * 3-2, 3) C2
of mydata
connect by substr (c2, level * 3-2, 3) is not null
and c1 = c1 prior
and prior dbms_random.random is not null;
C1 C2
---------- ---
1 ABC
0%
2 ABC
ABC 3
3
4 AB
5 ABC
5 DEF
5 GH
9 selected lines.
with mydata as
(
Select 1 c1, c2 'ABCD' Union double all the
Select 2, 'ABC' from dual union all
Select 3, 'ABCDE' from dual union all
Select option 4, "AB" dual union all
Select 5, "ABCDEFGH" of the double
)
Select a.c1, x.c2
of mydata one
, xmltable ("ora: tokenize($c2,",")")
passing regexp_replace (a.c2, '(.{1, 3}) \1 ',',') as "c2".
path of columns c2 varchar2 (30) '.'
) x
where x.c2 is not null;
C1 C2
---------- ------------------------------
1 ABC
0%
2 ABC
ABC 3
3
4 AB
5 ABC
5 DEF
5 GH
9 selected lines.
Edit: corrected the Xquery solution using a simplified regexp_replace.
Kind regards.
Alberto
-
APEX: Use the SQL query in the APEX_MAIL package
Hi all
I'm creating an application in which I want to extract records from table and send it to the user. Please help me on this.
Thank you
MartinHello I am,.
You can see the code below.
DECLARE
l_body_html CLOB.
l_body CLOB.
BEGIN
l_body: = 'Hello Daniel. "l_body_html: = '
'; ';Name of the law Law on ESCR Measures Act Name of the server Restart Date C1 in (select distinct (act_name), act_desc, act_steps, reboot_date servername HWC_CHK_SCHEDUELE where chk_name =: P2_SELECT_CHECKLIST and reboot_date =: P2_REBOOT_DATE)
loopl_body_html: = l_body_html | '
' || C1.act_name | ' ' || '' || C1.act_desc | ' ' || '' || C1.act_steps | ' ' || '' || C1. SERVER_NAME. ' ' || '' || C1.reboot_date | ' ';end loop;
l_body_html: = l_body_html | '
l_body_html: = l_body_html | '
' || "Thanks & Regards | '
';
l_body_html: = l_body_html | "Patel Dr.Jiten";() apex_mail. Send
p_to =>: P2_EMAIL,
P_FROM-online "[email protected]."
p_body-online l_body,
p_body_html-online l_body_html,
p_subj => "You must work on ABC named Checklist");
END; -
How to achieve this using the sql query?
Hello gurus,
I have a table like this
now my result should be like thisid name 1 a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9 i 10 j 11 k 12 l 13 m
How to achieve by sql query?id name id name id name 1 a 6 f 11 k 2 b 7 g 12 l 3 c 8 h 13 m 4 d 9 i 5 e 10 j
Thank you and best regards,
friend
Edited by: most wanted! February 22, 2012 05:55Hello
Did you mean this:
with a as (select 1 id ,'a' name from dual union all select 2 id ,'b' name from dual union all select 3 id ,'c' name from dual union all select 4 id ,'d' name from dual union all select 5 id ,'e' name from dual union all select 6 id ,'f' name from dual union all select 7 id ,'g' name from dual union all select 8 id ,'h' name from dual union all select 9 id ,'i' name from dual union all select 10 id ,'j' name from dual union all select 11 id ,'k' name from dual union all select 12 id ,'l' name from dual union all select 13 id ,'m' name from dual ) select id_1 ,name_1 ,id_2 ,name_2 ,id_3 ,name_3 from ( select id id_1 ,name name_1 ,lead(id,5) over (order by id) id_2 ,lead(name,5) over (order by id) name_2 ,lead(id,10) over (order by id) id_3 ,lead(name,10) over (order by id) name_3 ,rownum r from a ) where r <=5 D_1 NAME_1 ID_2 NAME_2 ID_3 NAME_3 ---------------------- ------ ---------------------- ------ ---------------------- ------ 1 a 6 f 11 k 2 b 7 g 12 l 3 c 8 h 13 m 4 d 9 i 5 e 10 j
Kind regards
Peter
-
How to scan multiple pages into a single document using the CanoScan LiDE 200?
How to scan multiple pages into a single document using the CanoScan LiDE 200?
I can't find a way to get them to analyze all the time, or a way to put together them later.
Hi dagda24,
You can scan multiple pages into a single document with the scan PDF option. Use the following steps to do:
1. open MP Navigator.
2. click on a Clcik.
3. click Save to PC.
4. change the Type of PDF file to PDF (multiple pages).
5 other changes, as needed, and then click Scan.
-
Dedicated Intel HD 4600 GPU vs... Failed to get AE to use the dedicated!
Running in this issue for all third-party plugins and I do not know what to do. I have a GTX 765 M in my laptop with a Core i7 CPU running Intel HD 4600 Graphics on it. I have nothing allows plugins to use the GTX and some outright crash using the integrated graphics card. Is there a way to get around this, or my next PC is an AMD processor?
Is there any other information that would be useful to diagnose the problem?
More simple than that, buried in the nVidia control center was an option to choose which programs use the iGPU against the dGPU. A dial-up during an update system (Win8.1) and was not aware he had the option to select. Solved the problem immediately and I have my speed back.
-
I just noticed that (in comparison to Internet Explorer): in IE, when you preferred a Web page, it uses the actual name of the Web page (for example, for this page, it would be "Ask a Question Firefox Help" as the name of the bookmark), but in Mozilla, it uses the URL as the name of the bookmark. I was wondering if it was possible to change my Mozilla settings so that it uses the name of the Web page as the bookmark name instead of the URL? I hope that everyone understands what I am getting? If anyone can help me, I would really appreciate it. Thank you.
Firefox uses the tag title for the name of the newly saved bookmark.
When I bookmark on this forum page I get this for the 'name' of the bookmark.
How can I get Mozilla to use the name of the page for the name of the real instead of the URL bookmark when I bookmark a page | Firefox Support Forum | Firefox help
-
So I just brought the creative plan Cloud photography student and Teacher Edition (one year) and no idea of how to get and start using the programs?
Hello
Go to creative.adobe.com and you identify with your Adobe ID
From there, you can download the applications you purchased.
Normally, you are taken there immediately after the purchase.
-
creation of database using the SQL command * more
Hello
This isn't a matter of urgency.
I learn the Oracle DBA. I have installed Oracle 9.2 in my windows system. And I'm trying to create a database using the SQL command.
OracleVersion: 9.2
Windows XP operating system
I get the error like below when executing the CREATE DATABASE command.CREATE DATABASE suri USER SYS identified by manager USER system identified by surendra LOGFILE GROUP 1 ('F:\Oracle\oradata\suri\redo01.log') SIZE 100M, GROUP 2 ('F:\Oracle\oradata\suri\redo02.log') SIZE 100M, GROUP 3 ('F:\Oracle\oradata\suri\redo03.log') SIZE 100M MAXLOGFILES 5 MAXLOGMEMBERS 5 MAXLOGHISTORY 1 MAXDATAFILES 100 MAXINSTANCES 1 CHARACTER SET US7ASCII NATIONAL CHARACTER SET AL16UTF16 DATAFILE 'F:\Oracle\oradata\suri\system01.dbf' size 200M EXTENT MANAGEMENT LOCAL UNDO tablespace undots datafile 'F:\Oracle\oradata\suri\undots01.dbf' size 200M DEFAULT TEMPORARY TABLESPACE tempts1 DATAFILE 'F:\Oracle\oradata\suri\temp01.dbf' SIZE 100M EXTENT MANAGEMENT LOCAL
I have validated the syntax but not able to find where is the error.ERROR at line 16: ORA-25139: invalid option for CREATE TEMPORARY TABLESPACE
Please let me know if you need more details.
Thanks in advance for your help.
Kind regards
SuriOracleVersion: 9.2
Why a so old version (and desupported)? In any case...
TEMPORARY TABLESPACE tempts1 DATAFILE 'F:\Oracle\oradata\suri\temp01.dbf' SIZE 100 M EXTENT MANAGEMENT LOCAL default
.. try change DATAFILE with TEMPFILE.
-
How to get the sql query result?
Hello
Currently I use LV2012 to connect to an Oracle database server. After the Oracle Express and Oracle ODBC driver facilities/settings made.
I managed to use the SQL command to query the data through my command prompt window.
Now the problem is, how to do the same task in Labview using database connectivity tools?
I have build a VI to query as being attached, but I have no idea of what range to use to get the result of the query.
Please help me ~ ~
Here is a piece of code that I use to test the SQL commands, you can use the part that retrieves the results of sql.
It is also possible to get the rear column headers, but it's for the next lesson!
;-)
Maybe you are looking for
-
Lenovo G50-70 plugged but not supported on windows 10
I upgraded my lenovo G 50-70 to 10 Windows. I encountered a problem, power laptop computer watch icon is plugged in, does not support. I couldn't find the drivers of energy management for windows 10 on support/download page. Help me solve the problem
-
Hello There are three edit field on my screen I want to know what edit field on focous. Thank you very much
-
15z HP touchscreen laptop: computer laptop brand new will not start
My brand new laptop just cameo yesterday and it keeps showing "Boot Menu" with 2 options (FreeDOS and Documents HP). If I choose option 1, which is "FreeDOS", it will show other 2 options: 1 - FreeDOS load including driver HIMM XMS-memory and 2 - loa
-
How do I remove items from psb files
I'm very new to Photoshop. I work with a file of psb in a psd. I got the appicontemplate.com psd file. I downloaded the IOS.I'm currently editing the psb file. I'm trying to remove what I call items out of him. I have looked into how to embed a
-
I have accidentally subscribed to a year long plan, paid monthly. I would like to be in place on a monthly plan. Because this isn't an 'upgrade', I'm not available change plan. How to "downgrade"? I guess I have to cancel my original plan and buy a n