Ask. UNION ALL on two tables of dummy data
I had a bit of SQL that joined a dynamic no cross table with another table of dummy data.
WITH tbl_job_data AS (SELECT 'N' argument1, 'Y' argument2, NULL argument3, 'Y' argument4 FROM DUAL) , tbl_params AS (SELECT 1 col_seq, 'From Project Number' col_prompt, NULL col_data, NULL col_attrib FROM DUAL UNION ALL SELECT 2 col_seq, 'To Project Number' col_prompt, NULL col_data, NULL col_attrib FROM DUAL UNION ALL SELECT 3 col_seq, 'Through Date' col_prompt, NULL col_data, NULL col_attrib FROM DUAL UNION ALL SELECT 4 col_seq, 'Summarize Cost' col_prompt, NULL col_data, NULL col_attrib FROM DUAL) SELECT NULL AS col_seq , NULL AS col_prompt , d.col_data , d.col_attrib FROM tbl_job_data UNPIVOT INCLUDE NULLS (col_attrib FOR col_data IN (argument1 , argument2 , argument3 , argument4) ) d UNION ALL SELECT tbl_params.col_seq , tbl_params.col_prompt , tbl_params.col_data , tbl_params.col_attrib FROM tbl_params; COL_SEQ COL_PROMPT COL_DATA COL_ATTRIB ---------- ------------------- --------- ---------- ARGUMENT1 N ARGUMENT2 Y ARGUMENT3 ARGUMENT4 Y 1 From Project Number 2 To Project Number 3 Through Date 4 Summarize Cost 8 rows selected.
Sorry to be very naïve and ignorant, but is be possible that I can get the output in 4 lines like that, by a union on 2 statements:
COL_SEQ COL_PROMPT COL_DATA COL_ATTRIB ---------- ------------------- --------- ---------- 1 From Project Number ARGUMENT1 N 2 To Project Number ARGUMENT2 Y 3 Through Date ARGUMENT3 4 Summarize Cost ARGUMENT4 Y
I guess not, because the 2 tables don't really have a lot in common with them, but I thought I'd ask.
Thank you
Previously, contributed to these requests by Frank Kulash
https://community.Oracle.com/thread/3810284 et
WITH
tbl_job_data AS
(SELECT "n" argument1, argument2 'Y', NULL argument3, 'Y' argument4)
OF THE DOUBLE
),
tbl_params AS
(SELECT 1 col_seq, number 'of the project"col_prompt, col_data, NULL, NULL col_attrib OF DOUBLE UNION ALL)
SELECT 2 col_seq, col_prompt 'for the project number", NULL, col_data, NULL col_attrib OF DOUBLE UNION ALL
SELECT 3 col_seq, col_prompt 'Date', NULL, col_data, NULL col_attrib OF DOUBLE UNION ALL
SELECT 4 col_seq, col_prompt "summarizes the cost", NULL, col_data, NULL FROM DUAL col_attrib
)
Select y.*, x.*
from (SELECT on col_seq (d.col_data control) row_number()
NULL AS col_prompt
d.col_data
d.col_attrib
OF tbl_job_data
MUST INCLUDE NULL VALUES
(col_attrib
FOR col_data IN (argument1
argument2
argument3
argument4)
) d
) x,.
(SELECT tbl_params.col_seq
tbl_params.col_prompt
tbl_params.col_data
tbl_params.col_attrib
OF tbl_params
) y
where x.col_seq = y.col_seq
COL_SEQ | COL_PROMPT | COL_DATA | COL_ATTRIB | COL_SEQ | COL_PROMPT | COL_DATA | COL_ATTRIB |
---|---|---|---|---|---|---|---|
1 | Project number | - | - | 1 | - | ARGUMENT1 | N |
2 | For the project number | - | - | 2 | - | ARGUMENT2 | THERE |
3 | By Date | - | - | 3 | - | ARGUMENT3 | - |
4 | Summarize the cost | - | - | 4 | - | ARGUMENT4 | THERE |
Concerning
Etbin
Tags: Database
Similar Questions
-
Please help me with the Alternative of queries to replace the UNION ALL for two queries
Hi all
I have the query to retrieve assets employees salary count and in so far as below:
Select ename, emp_no, sum (sal_till_2010), sum (sal_till_2014) of
(select emp_no, ename, salary as sal_till_2010, 0 as sal_till_2014 of employee e1
where effective_date < = 1 January 2010 ' and not exists (select 1 from e2 employee_deletion where e2.emp_no = e1.emp_no and e2.deletion_date < = January 1, 2010 "")
UNION ALL
Select ename, emp_no, 0 as sal_till_2010, salary as employee e1 sal_till_2014 - here is a dummy 0 salary until 2010 for the union of all the
where effective_date < = 1 January 2014 "and not exists (select 1 from e2 employee_deletion where e2.emp_no = e1.emp_no and e2.deletion_date < = 1 January 2014") "
Group of emp_no, ename;
In this query, I get the total salary until 2010 and until 2014 in the employee table, dates are dynamically passed to the procedure, and this can change.
But assume the date above and let me know the alternative of queries to improve performance because I use Union ALL and read the same table twice in the above query.
Advice me with request to read the table once to fetch the same data as the above query.
Thanks in advance.
Hello
Thanks for the display of the data of the sample; It's very useful!
I think OP wants something like this:
WITH cutoff_dates AS
(
SELECT TO_DATE (January 1, 2010 ', ' DD/MM/YYYY') AS cutoff_date, 2010 UNDER the label OF dual UNION ALL
SELECT TO_DATE (1 January 2014 ', "DD/MM/YYYY"), double 2014
)
SELECT e.emp_no, e.ename
, NVL (SUM (CASE WHEN c.label = 2010 THEN e.salary END), 0) AS sal_till_2010
, NVL (SUM (CASE WHEN c.label = 2014 THEN e.salary END), 0) AS sal_till_2014
E employee
JOIN cutoff_dates c ON e.effective_date<=>=>
WHERE DOES NOT EXIST)
SELECT 1
Of employee_deletion ed
WHERE ed.emp_no = e.emp_no
AND ed.deletion_date<=>=>
)
E.emp_no GROUP, e.ename
ORDER BY e.emp_no
;
Output of your sample data:
EMP_NO ENAME SAL_TILL_2010 SAL_TILL_2014
---------- ------ ------------- -------------
1 Mickey 450 0
2 Donald 750 0
-
Display data from two tables based on date criteria
Hi all
I have two tables, using these two tables and a few conditions I want to recover under result. Oracle version is (Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64 bit Production)
logon_histories_r table records the information of each user who connects to the system. Subscriber Details table contains all the information corresponding to subscriber_no, only 1 row should be returned.LOGON_ID USER_ID LOGON_TIME LOGON_TYPE SUBSCRIBER_NO CUSTOMER_ID 26063548 4528890298 4/5/2010 12:03:58 AM MSISDN GSM04528890298 581751708
I'm confused usage date condition for the table of the Subscriber, the input parameter date 04/04/2006 to 15/04/06
Select lh.logon_id, lh.user_id, lh.logon_time, lh.logon_type, subs.subscriber_no, subs.customer_id
of logon_histories_r lh, subscribed subs
where lh.logon_time > = to_date('05-04-2010','dd-mm-yyyy')--to_date('04-04-2006','dd-mm-yyyy')
and lh.logon_time < to_date('06-04-2010','dd-mm-yyyy')--to_date('15-01-2007','dd-mm-yyyy')
and lh.user_id = substr (subs.subscriber_no,-10);
If the date range is 04/05/2010 to 04/06/2010 then the data related to the BAN 581751708 must be the result,
If the date range is 04/04/2006 to 15/01/2007 data related to the BAN 502499502 must be the result.
Please find DDL and data relevant to these results. There are millions of records of Subscriber & logon_histories_r table, I am given appropriate providing a subscriber_id.
CREATE TABLE LOGON_HISTORIES_R ( LOGON_ID NUMBER(12) NOT NULL, USER_ID VARCHAR2(15 BYTE) NOT NULL, LOGON_TIME DATE NOT NULL, LOGOUT_TIME DATE, LOGOUT_METHOD VARCHAR2(15 BYTE), LOGON_TYPE VARCHAR2(15 BYTE) DEFAULT 'MSISDN' ); CREATE TABLE SUBSCRIBER ( SUBSCRIBER_NO VARCHAR2(20 BYTE) NOT NULL, CUSTOMER_ID NUMBER(9) NOT NULL, SYS_CREATION_DATE DATE NOT NULL, SYS_UPDATE_DATE DATE, OPERATOR_ID NUMBER(9), APPLICATION_ID CHAR(6 BYTE), DL_SERVICE_CODE CHAR(5 BYTE) NOT NULL, DL_UPDATE_STAMP NUMBER(4), EFFECTIVE_DATE DATE NOT NULL, INIT_ACTIVATION_DATE DATE NOT NULL, SUB_STATUS CHAR(1 BYTE) NOT NULL, SUB_STATUS_DATE DATE NOT NULL, ORIGINAL_INIT_DATE DATE NOT NULL, SUB_STATUS_LAST_ACT CHAR(3 BYTE), SUB_STATUS_RSN_CODE CHAR(4 BYTE), PRODUCT_TYPE CHAR(3 BYTE), CUSTOMER_BAN NUMBER(9), CTN_SEQ_NO NUMBER(9), REQ_ST_GRACE_PERIOD DATE, REQ_END_GRACE_PERIOD DATE, COMMIT_START_DATE DATE, COMMIT_END_DATE DATE, COMMIT_REASON_CODE CHAR(3 BYTE), COMMIT_ORIG_NO_MONTH NUMBER(3), SUSP_RC_RATE_TYPE CHAR(1 BYTE), CONTRACT_NO VARCHAR2(10 BYTE), CNT_SEQ_NO NUMBER(9), DEALER_CODE CHAR(5 BYTE), ORG_DEALER_CODE CHAR(5 BYTE), SALES_AGENT CHAR(5 BYTE), ORG_SALES_AGENT CHAR(5 BYTE), REQ_DEPOSIT_AMT NUMBER(13,2), LEADING_NUMBER VARCHAR2(20 BYTE), PABX_IND CHAR(1 BYTE), NEXT_CTN VARCHAR2(20 BYTE), NEXT_CTN_CHG_DATE DATE, PRV_CTN VARCHAR2(20 BYTE), PRV_CTN_CHG_DATE DATE, NEXT_BAN NUMBER(9), NEXT_BAN_MOVE_DATE DATE, PRV_BAN NUMBER(9), PRV_BAN_MOVE_DATE DATE, SUB_STS_ISSUE_DATE DATE, ACTIVATE_WAIVE_RSN CHAR(6 BYTE), EARLIEST_ACTV_DATE DATE, SUB_ACTV_LOCATION CHAR(4 BYTE), CUST_WATCH_LMT NUMBER(11,2), CUST_WATCH_DATE DATE, BASIC_WATCH_LMT NUMBER(11,2), CREDIT_WATCH_PIN_CD NUMBER(4), SUB_MARKET_CODE CHAR(3 BYTE) NOT NULL, LIMIT_RESERVED_DAYS NUMBER(4), FF_EXPIRATION_DATE DATE, FLEX_IND CHAR(1 BYTE), DUO_IND CHAR(1 BYTE), LISTED_IND CHAR(1 BYTE), SUB_DEPARTMENT_CD CHAR(4 BYTE), LAST_SUBS_DISC_DT DATE, LAST_SUBS_DISC_DT_UD DATE, LAST_SUBSCR_DISC_SN NUMBER(3), LAST_SUBSCR_DISC_SN_UD NUMBER(3), PNI VARCHAR2(10 BYTE), RMS_REF_STORE_ID CHAR(4 BYTE), RMS_REF_TYPE CHAR(1 BYTE), RMS_REF_OD NUMBER(9), DLR_ACT_FEE NUMBER(11,2), PREP_AMOUNT NUMBER(11,2), SUBSCRIBER_ID NUMBER(9) NOT NULL, SUB_LANG CHAR(2 BYTE), SMS_RCV_STYLE_CODE CHAR(2 BYTE), CONV_RUN_NO NUMBER(3), ALLOW_ADVERTISING_IND CHAR(1 BYTE), IVR_WRONG_ACCESS_NO NUMBER(2), THRESHOLD_AMT NUMBER(11,2), PUBLISH_LEVEL CHAR(30 BYTE), AUTO_RELEASE_IND CHAR(1 BYTE), CUST_WATCH_EFF_DATE DATE, CUST_WATCH_EXP_DATE DATE, OPERATOR_CW_LMT NUMBER(11,2), SEND_SMS_FOR_MATCH CHAR(1 BYTE), CPS_STATUS CHAR(1 BYTE), CPS_TRANSACTION NUMBER(3), CPS_TYPE NUMBER(3), ISP_PASS VARCHAR2(30 BYTE), ISP_TYPE CHAR(2 BYTE), OPERATOR_TMP_DATE DATE, OPERATOR_TMP_LMT NUMBER(11,2), SUB_ORG_CD CHAR(10 BYTE), ORG_MEMBER_NO VARCHAR2(20 BYTE) ); Insert into LOGON_HISTORIES_R (LOGON_ID, USER_ID, LOGON_TIME, LOGOUT_TIME, LOGOUT_METHOD, LOGON_TYPE) Values (26063548, '4528890298', TO_DATE('04/05/2010 00:03:58', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/05/2010 00:06:58', 'MM/DD/YYYY HH24:MI:SS'), NULL, 'MSISDN'); Insert into logon_histories_r (LOGON_ID, USER_ID, LOGON_TIME, LOGOUT_TIME, LOGOUT_METHOD, LOGON_TYPE) Values (2649592, '4528890298', TO_DATE('04/10/2006 19:19:20', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/10/2006 19:19:48', 'MM/DD/YYYY HH24:MI:SS'), 'TIMEOUT', 'MSISDN'); Insert into SUBSCRIBER (SUBSCRIBER_NO, CUSTOMER_ID, SYS_CREATION_DATE, SYS_UPDATE_DATE, OPERATOR_ID, APPLICATION_ID, DL_SERVICE_CODE, DL_UPDATE_STAMP, EFFECTIVE_DATE, INIT_ACTIVATION_DATE, SUB_STATUS, SUB_STATUS_DATE, ORIGINAL_INIT_DATE, SUB_STATUS_LAST_ACT, SUB_STATUS_RSN_CODE, PRODUCT_TYPE, CUSTOMER_BAN, CTN_SEQ_NO, REQ_ST_GRACE_PERIOD, REQ_END_GRACE_PERIOD, COMMIT_START_DATE, COMMIT_END_DATE, COMMIT_REASON_CODE, COMMIT_ORIG_NO_MONTH, SUSP_RC_RATE_TYPE, CONTRACT_NO, CNT_SEQ_NO, DEALER_CODE, ORG_DEALER_CODE, SALES_AGENT, ORG_SALES_AGENT, REQ_DEPOSIT_AMT, LEADING_NUMBER, PABX_IND, NEXT_CTN, NEXT_CTN_CHG_DATE, PRV_CTN, PRV_CTN_CHG_DATE, NEXT_BAN, NEXT_BAN_MOVE_DATE, PRV_BAN, PRV_BAN_MOVE_DATE, SUB_STS_ISSUE_DATE, ACTIVATE_WAIVE_RSN, EARLIEST_ACTV_DATE, SUB_ACTV_LOCATION, CUST_WATCH_LMT, CUST_WATCH_DATE, BASIC_WATCH_LMT, CREDIT_WATCH_PIN_CD, SUB_MARKET_CODE, LIMIT_RESERVED_DAYS, FF_EXPIRATION_DATE, FLEX_IND, DUO_IND, LISTED_IND, SUB_DEPARTMENT_CD, LAST_SUBS_DISC_DT, LAST_SUBS_DISC_DT_UD, LAST_SUBSCR_DISC_SN, LAST_SUBSCR_DISC_SN_UD, PNI, RMS_REF_STORE_ID, RMS_REF_TYPE, RMS_REF_OD, DLR_ACT_FEE, PREP_AMOUNT, SUBSCRIBER_ID, SUB_LANG, SMS_RCV_STYLE_CODE, CONV_RUN_NO, ALLOW_ADVERTISING_IND, IVR_WRONG_ACCESS_NO, THRESHOLD_AMT, PUBLISH_LEVEL, AUTO_RELEASE_IND, CUST_WATCH_EFF_DATE, CUST_WATCH_EXP_DATE, OPERATOR_CW_LMT, SEND_SMS_FOR_MATCH, CPS_STATUS, CPS_TRANSACTION, CPS_TYPE, ISP_PASS, ISP_TYPE, OPERATOR_TMP_DATE, OPERATOR_TMP_LMT, SUB_ORG_CD, ORG_MEMBER_NO) Values ('GSM04528890298', 110069191, TO_DATE('12/04/2001 17:06:17', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('01/01/2004 22:42:49', 'MM/DD/YYYY HH24:MI:SS'), NULL, 'FUTRX ', 'CS016', NULL, TO_DATE('01/02/2004 00:08:32', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('07/31/2000 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'C', TO_DATE('01/02/2004 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('07/31/2000 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CAN', 'CNP3', 'GSM', 110069191, 7013986, NULL, NULL, TO_DATE('07/31/2000 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('01/31/2001 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'PPD', 6, NULL, NULL, 1008631, 'DCNV ', 'DCNV ', 'DFLT ', 'DFLT ', 0, NULL, 'S', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, TO_DATE('01/02/2004 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), NULL, TO_DATE('07/31/2000 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'TEMO', 0, NULL, 0, NULL, 'TEL', NULL, NULL, 'N', 'N', 'Y', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 8635, 'DK', '01', 1, 'N', NULL, 0, '1234', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); Insert into SUBSCRIBER (SUBSCRIBER_NO, CUSTOMER_ID, SYS_CREATION_DATE, SYS_UPDATE_DATE, OPERATOR_ID, APPLICATION_ID, DL_SERVICE_CODE, DL_UPDATE_STAMP, EFFECTIVE_DATE, INIT_ACTIVATION_DATE, SUB_STATUS, SUB_STATUS_DATE, ORIGINAL_INIT_DATE, SUB_STATUS_LAST_ACT, SUB_STATUS_RSN_CODE, PRODUCT_TYPE, CUSTOMER_BAN, CTN_SEQ_NO, REQ_ST_GRACE_PERIOD, REQ_END_GRACE_PERIOD, COMMIT_START_DATE, COMMIT_END_DATE, COMMIT_REASON_CODE, COMMIT_ORIG_NO_MONTH, SUSP_RC_RATE_TYPE, CONTRACT_NO, CNT_SEQ_NO, DEALER_CODE, ORG_DEALER_CODE, SALES_AGENT, ORG_SALES_AGENT, REQ_DEPOSIT_AMT, LEADING_NUMBER, PABX_IND, NEXT_CTN, NEXT_CTN_CHG_DATE, PRV_CTN, PRV_CTN_CHG_DATE, NEXT_BAN, NEXT_BAN_MOVE_DATE, PRV_BAN, PRV_BAN_MOVE_DATE, SUB_STS_ISSUE_DATE, ACTIVATE_WAIVE_RSN, EARLIEST_ACTV_DATE, SUB_ACTV_LOCATION, CUST_WATCH_LMT, CUST_WATCH_DATE, BASIC_WATCH_LMT, CREDIT_WATCH_PIN_CD, SUB_MARKET_CODE, LIMIT_RESERVED_DAYS, FF_EXPIRATION_DATE, FLEX_IND, DUO_IND, LISTED_IND, SUB_DEPARTMENT_CD, LAST_SUBS_DISC_DT, LAST_SUBS_DISC_DT_UD, LAST_SUBSCR_DISC_SN, LAST_SUBSCR_DISC_SN_UD, PNI, RMS_REF_STORE_ID, RMS_REF_TYPE, RMS_REF_OD, DLR_ACT_FEE, PREP_AMOUNT, SUBSCRIBER_ID, SUB_LANG, SMS_RCV_STYLE_CODE, CONV_RUN_NO, ALLOW_ADVERTISING_IND, IVR_WRONG_ACCESS_NO, THRESHOLD_AMT, PUBLISH_LEVEL, AUTO_RELEASE_IND, CUST_WATCH_EFF_DATE, CUST_WATCH_EXP_DATE, OPERATOR_CW_LMT, SEND_SMS_FOR_MATCH, CPS_STATUS, CPS_TRANSACTION, CPS_TYPE, ISP_PASS, ISP_TYPE, OPERATOR_TMP_DATE, OPERATOR_TMP_LMT, SUB_ORG_CD, ORG_MEMBER_NO) Values ('GSM04528890298', 502499502, TO_DATE('12/05/2006 15:55:13', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('01/12/2007 00:45:22', 'MM/DD/YYYY HH24:MI:SS'), NULL, 'FUTRX ', 'CS058', NULL, TO_DATE('01/12/2007 00:45:22', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('12/05/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'C', TO_DATE('01/12/2007 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('12/05/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CCN', 'NP ', 'GSM', 502499502, 14419730, NULL, NULL, TO_DATE('12/05/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('06/04/2007 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'PPD', 6, NULL, '1035393', 6976424, '2311 ', '2311 ', 'DFLT ', 'DFLT ', NULL, '045', 'S', 'GSM04525210338', TO_DATE('01/12/2007 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), NULL, NULL, NULL, NULL, NULL, NULL, TO_DATE('01/12/2007 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), NULL, TO_DATE('12/05/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'TEMO', NULL, NULL, NULL, NULL, 'TEL', NULL, NULL, 'N', 'N', 'Y', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 6834900, 'DK', '01', NULL, 'N', NULL, 9999999.99, '4321', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); Insert into SUBSCRIBER (SUBSCRIBER_NO, CUSTOMER_ID, SYS_CREATION_DATE, SYS_UPDATE_DATE, OPERATOR_ID, APPLICATION_ID, DL_SERVICE_CODE, DL_UPDATE_STAMP, EFFECTIVE_DATE, INIT_ACTIVATION_DATE, SUB_STATUS, SUB_STATUS_DATE, ORIGINAL_INIT_DATE, SUB_STATUS_LAST_ACT, SUB_STATUS_RSN_CODE, PRODUCT_TYPE, CUSTOMER_BAN, CTN_SEQ_NO, REQ_ST_GRACE_PERIOD, REQ_END_GRACE_PERIOD, COMMIT_START_DATE, COMMIT_END_DATE, COMMIT_REASON_CODE, COMMIT_ORIG_NO_MONTH, SUSP_RC_RATE_TYPE, CONTRACT_NO, CNT_SEQ_NO, DEALER_CODE, ORG_DEALER_CODE, SALES_AGENT, ORG_SALES_AGENT, REQ_DEPOSIT_AMT, LEADING_NUMBER, PABX_IND, NEXT_CTN, NEXT_CTN_CHG_DATE, PRV_CTN, PRV_CTN_CHG_DATE, NEXT_BAN, NEXT_BAN_MOVE_DATE, PRV_BAN, PRV_BAN_MOVE_DATE, SUB_STS_ISSUE_DATE, ACTIVATE_WAIVE_RSN, EARLIEST_ACTV_DATE, SUB_ACTV_LOCATION, CUST_WATCH_LMT, CUST_WATCH_DATE, BASIC_WATCH_LMT, CREDIT_WATCH_PIN_CD, SUB_MARKET_CODE, LIMIT_RESERVED_DAYS, FF_EXPIRATION_DATE, FLEX_IND, DUO_IND, LISTED_IND, SUB_DEPARTMENT_CD, LAST_SUBS_DISC_DT, LAST_SUBS_DISC_DT_UD, LAST_SUBSCR_DISC_SN, LAST_SUBSCR_DISC_SN_UD, PNI, RMS_REF_STORE_ID, RMS_REF_TYPE, RMS_REF_OD, DLR_ACT_FEE, PREP_AMOUNT, SUBSCRIBER_ID, SUB_LANG, SMS_RCV_STYLE_CODE, CONV_RUN_NO, ALLOW_ADVERTISING_IND, IVR_WRONG_ACCESS_NO, THRESHOLD_AMT, PUBLISH_LEVEL, AUTO_RELEASE_IND, CUST_WATCH_EFF_DATE, CUST_WATCH_EXP_DATE, OPERATOR_CW_LMT, SEND_SMS_FOR_MATCH, CPS_STATUS, CPS_TRANSACTION, CPS_TYPE, ISP_PASS, ISP_TYPE, OPERATOR_TMP_DATE, OPERATOR_TMP_LMT, SUB_ORG_CD, ORG_MEMBER_NO) Values ('GSM04528890298', 581751708, TO_DATE('03/31/2010 19:10:33', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/01/2010 16:17:40', 'MM/DD/YYYY HH24:MI:SS'), 10077, NULL, 'CS009', NULL, TO_DATE('03/31/2010 19:10:33', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/31/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'A', TO_DATE('03/31/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/31/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'NAC', 'CA ', 'GSM', 581751708, 24798333, NULL, NULL, TO_DATE('03/31/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('09/29/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), NULL, 6, NULL, NULL, 12093584, '2357 ', '2357 ', 'DFLT ', 'DFLT ', NULL, '045', 'S', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, TO_DATE('03/31/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), NULL, TO_DATE('03/31/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'TEMO', NULL, NULL, NULL, NULL, 'TEL', NULL, TO_DATE('12/31/4700 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'N', 'N', 'Y', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 9474437, 'DK', '01', NULL, 'N', NULL, 999999999.99, '12', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); Insert into SUBSCRIBER (SUBSCRIBER_NO, CUSTOMER_ID, SYS_CREATION_DATE, SYS_UPDATE_DATE, OPERATOR_ID, APPLICATION_ID, DL_SERVICE_CODE, DL_UPDATE_STAMP, EFFECTIVE_DATE, INIT_ACTIVATION_DATE, SUB_STATUS, SUB_STATUS_DATE, ORIGINAL_INIT_DATE, SUB_STATUS_LAST_ACT, SUB_STATUS_RSN_CODE, PRODUCT_TYPE, CUSTOMER_BAN, CTN_SEQ_NO, REQ_ST_GRACE_PERIOD, REQ_END_GRACE_PERIOD, COMMIT_START_DATE, COMMIT_END_DATE, COMMIT_REASON_CODE, COMMIT_ORIG_NO_MONTH, SUSP_RC_RATE_TYPE, CONTRACT_NO, CNT_SEQ_NO, DEALER_CODE, ORG_DEALER_CODE, SALES_AGENT, ORG_SALES_AGENT, REQ_DEPOSIT_AMT, LEADING_NUMBER, PABX_IND, NEXT_CTN, NEXT_CTN_CHG_DATE, PRV_CTN, PRV_CTN_CHG_DATE, NEXT_BAN, NEXT_BAN_MOVE_DATE, PRV_BAN, PRV_BAN_MOVE_DATE, SUB_STS_ISSUE_DATE, ACTIVATE_WAIVE_RSN, EARLIEST_ACTV_DATE, SUB_ACTV_LOCATION, CUST_WATCH_LMT, CUST_WATCH_DATE, BASIC_WATCH_LMT, CREDIT_WATCH_PIN_CD, SUB_MARKET_CODE, LIMIT_RESERVED_DAYS, FF_EXPIRATION_DATE, FLEX_IND, DUO_IND, LISTED_IND, SUB_DEPARTMENT_CD, LAST_SUBS_DISC_DT, LAST_SUBS_DISC_DT_UD, LAST_SUBSCR_DISC_SN, LAST_SUBSCR_DISC_SN_UD, PNI, RMS_REF_STORE_ID, RMS_REF_TYPE, RMS_REF_OD, DLR_ACT_FEE, PREP_AMOUNT, SUBSCRIBER_ID, SUB_LANG, SMS_RCV_STYLE_CODE, CONV_RUN_NO, ALLOW_ADVERTISING_IND, IVR_WRONG_ACCESS_NO, THRESHOLD_AMT, PUBLISH_LEVEL, AUTO_RELEASE_IND, CUST_WATCH_EFF_DATE, CUST_WATCH_EXP_DATE, OPERATOR_CW_LMT, SEND_SMS_FOR_MATCH, CPS_STATUS, CPS_TRANSACTION, CPS_TYPE, ISP_PASS, ISP_TYPE, OPERATOR_TMP_DATE, OPERATOR_TMP_LMT, SUB_ORG_CD, ORG_MEMBER_NO) Values ('GSM04528890298', 816370100, TO_DATE('09/03/2005 10:12:13', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/14/2006 12:20:09', 'MM/DD/YYYY HH24:MI:SS'), 14462, NULL, 'CS016', NULL, TO_DATE('03/14/2006 12:20:08', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('09/03/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'C', TO_DATE('03/14/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('09/03/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CAN', 'CNP3', 'GSM', 816370100, 12575966, NULL, NULL, TO_DATE('09/03/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/02/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'PPD', 6, NULL, '690925', 3436964, '4243 ', '4243 ', 'DFLT ', 'DFLT ', NULL, '045', 'S', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, TO_DATE('03/14/2006 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), NULL, TO_DATE('09/03/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'TEMO', NULL, NULL, NULL, NULL, 'TEL', NULL, NULL, 'N', 'N', 'Y', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1436383, 'DK', '01', NULL, 'N', NULL, 9999999.99, '0', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
Hello
Welcome to the froum!
Thanks for posting the CREATE TABLE and INSERT! It's very nigra.
user12990691 wrote:
...
logon_histories_r table records the information of each user who connects to the system. Subscriber Details table contains all the information corresponding to subscriber_no, only 1 row should be returned.Do you mean a line by the user, or a line every time that you run the report, regardless of the number of users connected during the period that interests us?
Anyway, if there are multiple logons, how do you decide that one? Or the output of logon_histories_r columns will be a sort of composite?I'm confused usage date condition for the table of the Subscriber, the input parameter date 04/04/2006 to 15/04/06
Select lh.logon_id, lh.user_id, lh.logon_time, lh.logon_type, subs.subscriber_no, subs.customer_id
of logon_histories_r lh, subscribed subs
where lh.logon_time > = to_date('05-04-2010','dd-mm-yyyy')--to_date('04-04-2006','dd-mm-yyyy')
and lh.logon_time< to_date('06-04-2010','dd-mm-yyyy')="" --="">
and lh.user_id = substr (subs.subscriber_no,-10);Must LH.LOGON_TIME match something in the subscruber table? If so, you need to addsome extra join pathological.
For example, if lh.logon_time must be between d1 and d2 (where d1 and d2 are DATE columns), then:select lh.logon_id , lh.user_id , lh.logon_time , lh.logon_type , subs.subscriber_no , subs.customer_id from logon_histories_r lh , subscriber subs where lh.logon_time >= to_date ('05-04-2010','dd-mm-yyyy') -- to_date('04-04-2006','dd-mm-yyyy') and lh.logon_time < to_date ('06-04-2010','dd-mm-yyyy') -- to_date('15-01-2007','dd-mm-yyyy') and lh.user_id = substr (subs.subscriber_no, -10) and lh.logon_time >= subs.d1 -- New condition added and lh.logon_time <= subs.d2 -- New condition added ;
Please find DDL and data relevant to these results. There are millions of records of Subscriber & logon_histories_r table, I am given appropriate providing a subscriber_id.
That's smart, don't not post each row of the table: looks like you posted just enough to show what the problem is.
Try to do the same thing with the columns. Do not post every single column, just the columns that have something to do with the problem. -
Great way to add more than two tables on the data sources
Hello world
I would like to confirm everything that follows before doing so on my interface.
I work with an interface that is suppoused to pass data from some of the oracle tables in a DB X to an oracle table in a DB Y.
The target data store got a foreign key, that is why I have to download two tables on the area of thesources. Is this right? Should I tell the two tables sort? I mean those procurement.
I know this may seem a stupid question, but I like teo do things and to understand what I do in the future I can improve! If you can recommend me some additional reading on this I would really aopreciate your help and your advice.
Do not hesitate to contact me if additional information is required.
Best regards.
JaisonIf the form of files your multiple source tables are a unique entry in the table target, then they will certainly be linked. You can drag columns from a source model to another model of source to generate a join in the designer criteria.
-
Immagerie two tables without a CARPENTER
Hello
I had a little problem. I want to combine the two tables. But I don't need a Carpenter, cause that would give me wrong combined values.
I have a table working_hours which has the actual hours of work of employees. And a table times_absent that the absent employee time.
The two tables have the date and hours actual work and absent in addition to other tings inside.
Simple I want to combine these two tables in a large table.
Example:
Table working_hours:
Name - Date - hours-...
Mr.A - 2.5.2011 - 8-...
Mr.B - 2.5.2011 - 6-...
C 2.5.2011 - 7-...
Table times_absent:
Name - Date - day-...
Mr.A - 3.5.2011 - 1-...
Mr.B - 3.5.2011 - 2-...
Mr.B - 4.5.2011 - 2-...
New Table:
Name - Date - Working_Hours - Absent_Days-
Mr.A - 2.5.2011 - 8 - null - or some sort of dummy value XXX
Mr.A - 3.5.2011 - null-- 1
Mr.B - 2.5.2011 - 6 - null.
Mr.B - 3.5.2011 - null - 2-
Mr.B - 4.5.2011 - null - 2-
and so we.
Is there a possibility in the OWB to perform this task?
THXI did not understand your answer, but the OPERATOR PUT a couple IN a GROUP. What you need to do is connect your table 1 to table 2 for INgroup2 and INgroup1 (the two tables must have the same number and type of columns and the order is also important) and set your SET UNION operator, and that's all.
-
Is mapping dimension AWM - possible to load the data in two tables of entry?
Hi all
I have two tables ProductFamily (parent level) and products (child level).
I want to load a dimension of those tables where the parent-child relationships are maintained (I use AWM).
I created a map with these two entry tables, but the loaded data has no relationship.
So, how do I do that? Is it possible to load dimensions where different levels get data from multiple tables?
Is any type of Carpenter available in AWM?
Thank you
------------------------
A few Notes:
-I don't want to use OWB here that my data are clean
-In AWM, when I loaded the data in a single view that contains two tables of input data, it worked fine. But it's my worst case option.You must use Dimension option in snowflake in the mapping screen of size for the Product Dimension (as opposed to the default style mapping - star schema dimension).
This will modify map entries to include a separate parent for each level of hierarchy level / that is to say, for each level of hierarchy / (unless a higher level of the hierarchy), you must specify the parent level key in addition to the key current level, code/name/description/other attributes etc.
You can make the mapping or... use the icons at the top of the map screen.
mode drag/drop by dragging the relational column on dimension - level/hierarchy/attribute model
-or-
the table expression mapping mode that gives the same effect... by dragging a column on an attribute defined in the. . the format of
. HTH
ShankarNote1: Complete the mapping of a sudden... B & w switching mapping modes cause the mappings to reset.
NOTE2: assumes that your data are correct foreign key table parent level: ProductFamily exists in the child level table: products. -
How to select a record in one table to manipulate data in a database?
Hello community,
Using 32-bit Labview 2015.
I created a user interface that runs a query and retrieves my table from a sql database.
I want to be able to manage only one record at a time by selecting the record in my table and then manipulate the data according to the needs.
Whenever the user runs a query, I want as the first record in the table to be selected / highlighted.
I want an indicator that is currently active.
Then a click of a button, to be able to scroll the actively selected record.
Once I have the selected record, I want a way to write a query to edit or delete the record.
Is attached a photo of my query to select all of my table and connect data in my table (results).
Attached a photo of my painting showing the timeline of my sql database.
What is the best way to go on a record selection in a table and the modification of data with a query?
Any help would be greatly appreciated.
Thank you
I guess that's not a table, but multi-column listbox.
Right click, select--> highlight whole line selection Mode
The value of the multicolumn listbox is the row index - you can write a local variable to highlight the line, the event structure to handle the user clicking on, etc.
If you enable the property editable ListBox cells, you can allow users to edit the items of the listbox.
If you want to get the data in row, you hint REF table and work with the array of strings in row - convert it to cluster, etc..
I don't know, what type of data, it is, how you structure the database looks like, I don't even know if you use the wrapper to work with the database, I can't write queries for you.
Something like Update Tablica Set Serial = '5' where ID = '22';
-
Hello
I have two tables with the same data structures and I want the two to the union. The problem I faced with union is the results are joined and it is difficult to distinguish which set of result belongs to which table:
for example
Select * from staff
Union
Select * from employees
Jan - 06 Division
Activity 10
Company 4
6 marketing
Marketing 3
5 finance
Finance 2
Is there a way to display the above results like
Jan - 06 Division
"Staff".
Activity 10
6 marketing
5 finance
"Outgoing".
Company 4
Marketing 3
Finance 2
The difference is there is a line break, showing the separation of staff and outgoing. Can anyone help?
Thank youDoes that help?
select 'STAFF' TABLE_NAME, s.* from staff s union select 'EMPLOYEES' TABLE_NAME, e.* from employees e
-
Select different columns using union all
I'm trying to select all the records of two table
Select A, B, C from table1
Union of all the
Select A, B, D, E, F from table2
I get results A, B, C columns but not D, E, F.
What should I do to get all the columns in the result. as A, B, C, D, E, F
Thank you
SKHello
That's what you asked for:
select Total_Customer_Qty, NULL AS Total_Supplier_Qty, Item_number, Org,item_id from table1; union all select NULL AS Total_Customer_Qty, Total_Supplier_Qty, Item_number, Org,item_id from table2;
I hope that's what you want, too.
If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using. -
getting data between two tables
Hi everyone, I need help with a query that seems simple, but I can't understand. consider the following data.
with data as (
s élire 802 cd from dual union all
select 803 cd from dual union all
select 804 cd from dual
data2 as
( select 804 cd from dual )
I want to join the two tables so that the result will be as follows:
in the above data, we can see that 804 is common in both tables. in this case, the output should be 804.
Similarly, if 2 data include the following:
data2 as
( select 804 cd from dual union all
Select 803 cd from dual
)
the output is then 803 804.
Now consider the following data
with data as (
s élire 802 cd from dual union all
select 803 cd from dual union all
select 804 cd from dual
)
take data2 table is empty
I want to join the two tables, and in this case, the output should be 802,803,804. data2 table is empty, then the default behavior is to get all the data in the data table. Since there is no line that corresponds to rows in the data table,
the default behavior is to display output all data in the data table. in this case 802,803,804
can someone write a query for this?
Hello
elmasduro wrote:
Hi Frank, thanks for the request. These are very good questions. Here are the answers
What happens if data2 rows, but none of them match data CD?
It won't happen because the integrity of the data.
...
I see it; a data line 2 will be in the data. You have a FOREIGN KEY constraint, or something similar, so if cd = 804 exists in database2, then it must also exist in the data.
What happens if the data is empty and data2 is not?
If data is empty and data2 is not, then the data2 data should be released.
for example
with the data as)
data table is empty
data2 as
(select cd 804 Union double all the)
Select cd 805 double
)
When you join data and data2 account with the above data, then the output should be 804 805. data2 data should be the display if the data table is empty. ...
Doesn't that contradict what you said earlier? Previously, it seemed to say that each row of data2 will be in the data, but now you give an example where all data2 lines are not in the data.
If the first is true, then the solution in response #2 should work.
If the latter is true, you can change the query like this:
WITH got_r_num AS
(
SELECT NVL (d.cd, d2.cd) AS cd
DENSE_RANK () (ORDER IN CASE
WHEN d.cd IS NOT NULL
AND d2.cd IS NOT NULL
THEN "A".
WHEN d.cd IS NOT NULL
THEN 'B '.
ANOTHER 'C '.
END
) AS r_num
DATA d
FULL OUTER JOIN data2 d2 ON d.cd = d2.cd
)
SELECT cd
OF got_r_num
WHERE r_num = 1
ORDER BY cd
;
-
How to create a select statement to the data in two tables?
Hi allTable 1
ID YEAR
758 2013
Table 2
ID YEAR
758 2014
I want to create some that translates into two lines: function that does this?
ID YEAR
758 2014
758 2013
Thank you, best regards.
Hello
Perhaps a select * from table1 UNION ALL select * from table2 will help you.
concerning
Kay -
Union all with addistional field
Hello
Maybe this is a stupid question.
I have two tables with 22 columns.
Another table with 23 columns
I want to combine these two tables using union all.
In the first picture, I want back "NA" as the last field.
In the second table, last column is varchar2.
Instead of every column one by one and if I use select * in two queries and add "NA" to one?
I want the union two queries can order and use it with the clause to retrieve values based on conditions somany.
So I have to specify the names of column three times.
I use oracle 10g
Hello Krishna,
Try
select t1.*, 'NA' as
from table1 t1 union select t2.* from table2 t2; concerning
Kay
-
Delete rows in a table when the columns from two tables match
Hello
I have following two tables.
===========================================
create the table empbooth as
(
Select 1 empid, 1 double cabin Union all the
Select option 2, Union 1 double all the
Select 3, Union 1 double all the
Select option 4, Union 2 double all the
Select option 5, 2 double
);
create the table attsht as
(
Select 1 empid, 240 reg, 0 unpaid all double union
Select option 2, reg 200, 0 unpaid of all the double union
Select 3, 240 reg, 0 unpaid all double them union
Select 4 480 reg, 0 unpaid all double union
Select 5 240 reg, unpaid double 0
);
=================================================
I want to remove rows from attsht where corresponding booth (which is stored in the empbooth table) is 1.
The condition is 'where attsht.empid = empbooth.empid and empbooth.booth = 1 '.
I use oracle 10g.
Help, please
delete from attsht where a.empid in (select b.empid from empbooth b where b.booth = 1)
or
remove from attsht a
where exists (select null
of empbooth b
where b.booth = 1
and b.empid = a.empid)
-
Valid time intervals: two tables intersect documents
Benefits:
I have two tables:
AVAILABILITY (ALLOCATION A_ID, START_TIME, END_TIME, ID_RESSOURCE)
TASK (T_ID, START_TIME, END_TIME, ID_RESSOURCE)
My final request should print:
Id_ressource, DAY_OF_WEEK, MYDATE, DURATION (in hours)
Semantics back: "give me all the time slots available; Time slot available to the general public is the time range that does not contain a task"
1. in the tables above START_TIME, END_TIME are of type DATE and they contain a timestamp that is to say:
SELECT to_char (START_TIME, 'HH24 MMDDYYYY') from the AVAILABILITY/TASK
would print something like
09232014 14:17
2. in the tables above time START_TIME and END_TIME are of the same date and END_TIME > START_TIME IE
START_TIME = 09232014 14:17
END_TIME = 09232014 15:17
no need to check that
3. If for some date there are TASK BOTH records and AVAILABILITY, then it must be:
TASK. End_time < = AVAILABILITY. End_time and TASK. Start_time = > AVAILABILITY. START_TIME
In other words, JOB registration is still "inside" free and BUSY folder
I need time slots which are essentially output
-All available records that do not contain a ' ' tasks.
AVAILABILITY. Id_ressource, to_char (AVAILABILITY. Start_time, 'DAY') as DAY_OF_WEEK, AVAILABILITY. Start_time as MYDATE, (AVAILABILITY. END_TIME-AVAILABILITY. Start_time) * 24 as DURATION
AND
-If the free and busy folder contains task (see 3) then there are 2 two time intervals resulting (Yes the duration can be 0)
AVAILABILITY. Id_ressource, to_char (AVAILABILITY. Start_time, 'DAY') as DAY_OF_WEEK, AVAILABILITY. Start_time as MYDATE, (TASK. START_TIME-AVAILABILITY. Start_time) * 24 as DURATION
and
AVAILABILITY. Id_ressource, to_char (AVAILABILITY. Start_time, 'DAY') as DAY_OF_WEEK, AVAILABILITY. Start_time as MYDATE, (AVAILABILITY. END_TIME-TASK. End_time) * 24 as DURATION
Hope the above makes sense. What is the best, more rapid SQL?
Hello
Here's a way to do it:
WITH union_data AS
(
SELECT id_ressource, change_time, change_val
AVAILABILITY
UNPIVOT (change_time
FOR change_val IN (start_time AS 1
end_time AS - 1
)
)
UNION ALL
SELECT id_ressource, change_time, change_val
TASK
UNPIVOT (change_time
FOR change_val IN (start_time AS 1
end_time AS - 1
)
)
)
got_change_sum AS
(
SELECT id_ressource
change_time
SUM (change_val) OVER (PARTITION BY id_ressource
ORDER BY change_time
) AS change_sum
Advance (change_time) OVER (PARTITION BY id_ressource
ORDER BY change_time
) - change_time AS long
Of union_data
)
SELECT id_ressource
, TO_CHAR (change_time, 'fmDay, FMMM-DD-YYYY') AS available_date
Duration * 24 AS available_hours
OF got_change_sum
WHERE change_sum = 1
ORDER BY id_ressource
change_time
;
To see how it works, view the results of each auxiliary request individually.
You will see that the union_data product has all the points where either avaialablity or a task changes. The column change_val is + 1 availability or a task at the beginning and - 1, when it ends. When the cumulative sum of those is 0, this means that there is no availability. When the accumulated amount is > 1, this means a task is underway. We are interested in the places where the cumulative sum of change_val is exactly 1, sense that a period which started (but not yet completed) and that there is a net 0 current tasks.
This solution is NOT the value of start_time and end_time in the same day of calendar and tasks for the same resource may overlap.
-
Take the difference of two tables
Hello
I have two tables where in I need to take the difference between the two columns of different tables and show as decimal below:
Table A
Name, salary
x 10.5
y - 10.32
z 5
Table B
Name, salary
x 10.5
y - 10.32
z 3
a 12
Output:
Name_A, Name_B, salary, remarks
x, x, 0, no diff
y, y, 0, no diff
z, z, 2 Diff is here
, one, no data, no data from the previous
Hello
Try ythis:
with table_a as
(
SELECT 'X' NAME, SALARY, 10.5 DUAL UNION ALL
SELECT THE NAME OF 'Y',-10.32 SALARY OF DOUBLE UNION ALL
SELECT THE NAME OF 'Z', 5 DOUBLE SALARY
)
table_B as
(
SELECT 'X' NAME, SALARY, 10.5 DUAL UNION ALL
SELECT THE NAME OF 'Y',-10.32 SALARY OF DOUBLE UNION ALL
SELECT THE NAME OF 'Z', 3 DOUBLE UNION ALL SALARIES
SELECT 'A' NAME, SALARY 12 DUAL FROM
)
SELECT
COALESCE(A.NAME,B.NAME) NAME
, NVL (TO_CHAR (A.SALARY - B.SALARY), 'NO DATA') SALARY
, CASE WHEN A.SALARY - B.SALARY = 0 THEN 'NO DIFFERENCE '.
WHEN B.SID IS NULL, "NO DATA OF THE PREVIOUS.
WHERE B.NAME IS NULL, "NO DATA FROM NEXT.
ANOTHER 'DIFFERENCE IS THERE.
END NOTEOf
TABLE_A HAS
TABLE_B FULL OUTER JOIN B ON (B.SID = B.NAME)
;NAME SALARY NOTE
---- ---------------------------------------- ---------------------
X 0 NO DIFFERENCE
Y 0 NO DIFFERENCE
Z 2 THE DIFFERENCE IS THERE
A NUMBER OF DATA NO DATA FROM THE PREVIOUSKind regards
Peter
Maybe you are looking for
-
Firefox constantly redirects my computer to otherpages
After clicking on a link I am redirected to other independent commercial sites. I can close each and eventually bring up the selected site. I have installed adware blocks, reinstalled Firefox 30 without success. Reluctantly, I changed my default brow
-
Remote Access Time capsule with windows 10 pc
I have my time Capsule connected to the router of the provider internet I easily access from inside my home network and with a Mac, I'm not able to access remotely with my Windows 10 PC and my iPad Time Capsule (I only am not able to Set up hold File
-
Cannot find fanny on Skype on my phone
I was messaging a friend on Skype when o met Fanny and me I was enjoying myself much with them, BUT I get to come back or smilies someone else has this problem or can help please [The update by the moderator topic title should be more descriptive. [O
-
Update Windows failure...?
whenever I have install updates ittells me that he didn't and don't stop trying to get me again.
-
Acer Aspire HD E1 graphics driver - 571-4000
Hello, I tried to update the HD Graphics 4000 driver in my Acer Aspire E1-571 and I'm able to get the latest version of the driver works very well from the Acer support page. However, this driver is almost 3 and a half years now or dates from 2012 wi