I have a big query which needs some tuning. I can't see any place where there is any scope for optimizing. The recommended and required stats are all collected. Could you please have a look and suggest. Its doing a snapshot dump when submitting the query through informatica.Below is the error we are getting:
3610 Internal error: Please do not resubmit the last request. SubCode, CrashCode: 0, 3651
SELECT
TD.INFORMATION_DATE AS INFORMATION_DATE ,
TD.PROCESSING_DATE AS PROCESS_DATE ,
NULL AS EXCEPTION_REASON_POA ,
NULL AS EXCEPTION_REASON_CUST ,
NULL AS EXCEPTION_REASON_SITE ,
NULL AS EXCEPTION_REASON_SIC ,
FRET.FIC_REPORTING_ENTITY_ID AS REPORTING_ENTITY_ID ,
NULL AS REPORTERS_REFERENCE_NO ,
'CTR' AS REPORT_CODE ,
NULL AS REPORT_SUBMISSION_DATE ,
TD.TRANSACTION_EFFECTIVE_DATE AS TRANSACTION_DATE ,
TD.TRANSACTION_AMT AS TRANSACTION_AMOUNT ,
TD.TRANSACTION_CURRENCY_CODE AS TXN_CURRENCY_CODE ,
CASE
WHEN CFT.FUNCTION_TYPE_CODE IN ( 'CDK' , 'MDK' , 'CW' , 'CWA' ,
'CDMK' , 'CWC' , 'CWR' , 'CWS' , 'QDAK' , 'QE' , 'TCS' , 'CDF' ,
'BNRP' , 'NRW' , 'FBS' , 'BNTF' , 'BNSP' , 'TOTP' , 'TOTB' ,
'BNSL' , 'CDCK' ) THEN 'CASH OUT'
ELSE 'CASH IN'
END AS TRANSACTION_DIRECTION ,
TD.TRANSACTION_SOURCE_TYPE_DESC AS TXN_TYPE ,
TD.FUNCTION_TYPE_DESC AS FUNCTION_CODE ,
TD.TRANSACTION_BRANCH AS TXN_BRANCH ,
TD.ACCOUNT_BRANCH AS ACCOUNT_BRANCH ,
TD.ACCOUNT_NUMBER AS ACCOUNT_NUMBER ,
TD.BRAND_TYPE_DESC AS ACCOUNT_TYPE ,
TD.TRANSACTION_ADDRESS AS TXN_ADDRESS ,
TD.TRANSACTION_CITY_NAME AS TXN_CITY ,
TD.TRANSACTION_POSTAL_CODE AS TXN_POSTAL_CODE ,
TD.TRANSACTION_COUNTRY_CODE AS TXN_COUNTRY_CODE ,
NULL AS TXN_PROVINCE ,
NULL AS CUSTOMER_TYPE_GROUP_CODE ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.NAME_INITIALS
ELSE NULL
END AS CUSTOMER_TITLE ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.GIVEN_NAME
ELSE NULL
END AS FIRST_NAME ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.SURNAME
ELSE NULL
END AS LAST_NAME ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.BIRTH_DATE
ELSE NULL
END AS BIRTHDATE ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.COUNTRY_OF_NATIONALITY_CODE
ELSE NULL
END AS NATIONALITY ,
CEC.E_MAIL_USER_ID AS EMAIL_ADDRESS ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.INDV_OCCUPATION_TYPE_DESC
ELSE NULL
END AS OCCUPATION ,
CPC_BP.TELEPHONE_DIAL_CODE AS BUSINESS_DIAL_CODE ,
CPC_BP.TELEPHONE_NUM AS BUSINESS_PHONE_NUMBER ,
CPC_HP.TELEPHONE_DIAL_CODE AS RESIDENTIAL_DIAL_CODE ,
CPC_HP.TELEPHONE_NUM AS RESIDENTIAL_PHONE_NUMBER ,
OC.PRACTICE_NUMBER AS PRACTISE_NUMBER ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.FIC_IDENTIFICATION_TYPE_CODE
ELSE NULL
END AS ID_TYPE ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.IDENTIFICATION_NUM
ELSE NULL
END AS ID_NUMBER ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.COUNTRY_PASSPORT_ISSUED_NAME
ELSE NULL
END AS PASSP_ISD_COUNTRY_CODE ,
CAC_RA.ADDRESS_NAME_1 AS PHYSICAL_ADDR_LINE ,
CAC_RA.CITY_NAME AS PHYSICAL_CITY ,
CAC_RA.POSTCODE_AREA AS PHYSICAL_POST_CODE ,
NULL AS BRAND_SHORT_NAME_ACCOUNT ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.UNIQUE_ID_IN_SOURCE_SYSTEM
ELSE NULL
END AS CUSTOMER_KEY ,
TD.ACCOUNTABLE_INSTITUTION_CODE AS ACCOUNTABLE_INSTIT_CODE ,
TD.SOURCE_SYSTEM_DESC AS SOURCE_SYSTEM ,
TD.TRANSACTION_QTY AS TXN_COUNT_TOT ,
OC.SIC_TYPE_DESC AS TYPE_OF_BUSINESS ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.UNIQUE_ID_IN_SOURCE_SYSTEM
ELSE NULL
END AS SIG_CUSTOMER_KEY ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.CUSTOMER_TYPE_CODE
ELSE NULL
END AS SIG_CUSTOMER_TYPE_CODE ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.NAME_INITIALS
ELSE NULL
END AS SIG_TITLE ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.GIVEN_NAME
ELSE NULL
END AS SIG_FIRST_NAME ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.SURNAME
ELSE NULL
END AS SIG_LAST_NAME ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.BIRTH_DATE
ELSE NULL
END AS SIG_BIRTHDATE ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.COUNTRY_OF_NATIONALITY_CODE
ELSE NULL
END AS SIG_NATIONALITY , CEC.E_MAIL_USER_ID AS SIG_EMAIL_ADDRESS ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.INDV_OCCUPATION_TYPE_DESC
ELSE NULL
END AS SIG_OCCUPATION ,
CPC_BP.TELEPHONE_DIAL_CODE AS SIG_BUSINESS_DIAL_CODE ,
CPC_BP.TELEPHONE_NUM AS SIG_BUSINESS_PHONE_NUMBER ,
CPC_HP.TELEPHONE_DIAL_CODE AS SIG_RESIDENTIAL_DIAL ,
CPC_HP.TELEPHONE_NUM AS SIG_RESIDENTIAL_PHONE_NUM ,
OC.PRACTICE_NUMBER AS SIG_PRACTISE_NUMBER ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.FIC_IDENTIFICATION_TYPE_CODE
ELSE NULL
END AS SIG_ID_TYPE ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.IDENTIFICATION_NUM
ELSE NULL
END AS SIG_ID_NUMBER ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.COUNTRY_PASSPORT_ISSUED_NAME
ELSE NULL
END AS SIG_PASSP_ISD_CNTRY_CODE ,
CAC_RA.ADDRESS_NAME_1 AS SIG_PHYSICAL_ADDR_LINE ,
CAC_RA.CITY_NAME AS SIG_PHYSICAL_CITY ,
CAC_RA.POSTCODE_AREA AS SIG_PHYSICAL_POST_CODE ,
NULL AS ERROR_STATUS ,
NULL AS BATCH_ID ,
NULL AS FORMAT_TYPE ,
NULL AS BATCH_SORT ,
TD.TRANSACTION_BRANCH AS ACCT_TXN_SITE_ZERO ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.CUSTOMER_TYPE_CODE
ELSE NULL
END AS CUSTOMER_TYPE_CODE ,
NULL AS RESUBMISION_STATUS ,
NULL AS BATCH_ERROR_STATUS ,
NULL AS FIC_RESUBMIT ,
TD.TRANSACTION_COUNTRY_CODE AS COUNTRY_CODE_FROM_CTR ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.COUNTRY_OF_RESIDENCE_CODE
ELSE NULL
END AS SIG_COUNTRY_CODE ,
TD.TRANSACTION_CUSTOMER_KEY AS TXN_CUSTOMER_KEY ,
TD.PARTY_DETAILS AS REPORT_PARTIES ,
NULL AS STATUS_COMMENT ,
NULL AS PROPERTY_SIZE ,
TD.SIZE_UNIT_OF_MEASUREMENT AS SIZE_UNIT_OF_MEASUREMENT ,
NULL AS REGISTRATION_DATE ,
OC.ORG_REGISTRATION_NUM AS REGISTRATION_NUMBER ,
NULL AS ITEM_ID_NUMBER ,
NULL AS ADDITIONAL_COMMENTS ,
TD.ITEM_TYPE_CODE AS ITEM_DESCRIPTION ,
NULL AS PREVIOUS_REGISTERED_TO ,
NULL AS CURRENT_REGISTERED_TO ,
TD.ESTIMATED_VAL_AMT AS ESTIMATED_VALUE ,
NULL AS DISPOSED_VALUE ,
NULL AS REPORTING_PERSON ,
TD.TRANSACTION_COUNTRY_CODE AS BANK_COUNTRY ,
TD.ITEM_TYPE_CODE AS ITEM_TYPE ,
NULL AS ITEM_MAKE ,
NULL AS ITEM_REGISTRATION_NUMBER ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.SURNAME
ELSE NULL
END AS MOTHERS_NAME ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.SOCIAL_SECURITY_NUMBER
ELSE NULL
END AS SOCIAL_SECURITY_NUMBER ,
CAC_EA.ADDRESS_NAME_1 AS EMPLOYER_ADDRESS_ID ,
CPC_BP.TELEPHONE_NUM AS EMPLOYER_PHONE_ID ,
NULL AS SWIFT_CODE ,
NULL AS NON_BANKING_INSTIT_FLAG ,
NULL AS SIG_ROLE ,
TD.POST_TRANS_ACC_BAL_AMT AS BALANCE ,
TD.ACCOUNT_NAME AS ACCOUNT_NAME ,
NULL AS INT_BANK_ACCOUNT_NUMBER ,
NULL AS PRIMARY_CUSTOMER_FLAG ,
TD.TRANS_STATUS_TYPE_CODE AS STATUS_CODE ,
OC.FIC_ENTITY_LEGAL_FORM AS INCORPORATION_LEGAL_FORM ,
CWAC_BW.UNIVERSAL_RESOURCE_LOCATOR AS INTERNET_WEB_SITE ,
OC.INVOLVED_PARTY_NAME AS TRADING_NAME ,
NULL AS DATE_OF_INCORPORATION ,
NULL AS DATE_BUSINESS_CLOSED ,
NULL AS BUSINESS_CLOSED_FLAG ,
CAC_PA.ADDRESS_NAME_1 AS POSTAL_ADDRESS_LINE_2 ,
CAC_PA.CITY_NAME AS POSTAL_ADDRESS_LINE_3 ,
NULL AS TYPE_OF_FUNDS ,
NULL AS TXN_CONDUCTOR ,
NULL AS TYPE_OF_FUNDS_DESC ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.DECEASED_FLAG
ELSE NULL
END AS DECEASED_FLAG ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.IDENTIFICATION_ISSUE_DATE
ELSE NULL
END AS ID_ISSUE_DATE ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.INDV_TEMP_RESIDENCE_EXP_DATE
ELSE NULL
END AS ID_EXPIRY_DATE , NULL AS ISSUING_AUTHORITY_NAME ,
CASE
WHEN IC_N.SOURCE_FILE_NAME = 'SIG' THEN IC_N.DEATH_NOTIFICATION_DATE
ELSE NULL
END AS DATE_OF_DEATH ,
OC.VALUE_ADDED_TAX_NUM AS VAT_REGISTRATION_NUMBER ,
NULL AS SOURCE_OF_WEALTH ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.GIVEN_NAME
ELSE NULL
END AS MIDDLE_NAME , TD.ACCOUNT_BRANCH AS DOMICILE_SITE_CODE ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.COUNTRY_PASSPORT_ISSUED_CODE
ELSE NULL
END AS COUNTRY_PASSPORT_ISSUED ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.COUNTRY_OF_RESIDENCE_CODE
ELSE NULL
END AS COUNTRY_OF_RESIDENCE ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.NAME_INITIALS
ELSE NULL
END AS INITIALS ,
CPC_BP.TELEPHONE_NUM (NAMED ASPHONE_EXTENSION_NUMBER ) ,
NULL AS STR_CLASIFICATION_IND ,
NULL AS TRANSACTION_DESCRIPTION ,
NULL AS TXN_AUTHORISOR ,
TD.TRANSACTION_EFFECTIVE_DATE AS VALUE_DATE ,
NULL AS TRANSACTION_MODE_COMMENT ,
TD.PARTY_DETAILS AS PARTY_DETAILS ,
NULL AS GOODS_SERVICES_LINKED ,
NULL AS TELLER_NUMBER ,
TD.AR_OPEN_DATE AS DATE_ACCOUNT_OPENED ,
OC.ORG_TAX_IDENTIFIED_NUM AS TAX_NUMBER ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.GENDER_DESC
ELSE NULL
END AS GENDER ,
CASE
WHEN IC_N.SOURCE_FILE_NAME <> 'SIG' THEN IC_N.COUNTRY_OF_BIRTH_NAME
ELSE NULL
END AS COUNTRY_OF_BIRTH ,
TD.TRANSACTION_CURRENCY_CODE AS CURRENCY_CODE ,
TD.SOURCE_SYSTEM_CODE AS SOURCE_SYSTEM_CODE ,
CURRENT_TIMESTAMP( 6 ) AS DW_LOAD_TIMESTAMP ,
NULL AS DW_INVALIDATED_TIMESTAMP
FROM X_TRANS.TRANSACTION_DAILY TD
LEFT OUTER JOIN X_REF.COMBD_FUNCTION_TYPE CFT
ON CFT.FUNCTION_TYPE_DESC = TD.FUNCTION_TYPE_DESC
AND CFT.EFFECTIVE_END_DATE = '3499-12-31'
LEFT OUTER JOIN X_REF.FIC_REPORTING_ENTITY_TYPE FRET
ON TD.ACCOUNTABLE_INSTITUTION_CODE = FRET.FIC_REPORTING_ENTITY_ID
AND FRET.EFFECTIVE_END_DATE = '3499-12-31'
LEFT OUTER JOIN X_TRANS.INDIVIDUAL_CURRENT IC_N
ON TD.INVOLVED_PARTY_ID = IC_N.INVOLVED_PARTY_ID
LEFT OUTER JOIN X_TRANS.CUSTOMER_EMAIL_CURRENT CEC
ON TD.INVOLVED_PARTY_ID = CEC.INVOLVED_PARTY_ID
LEFT OUTER JOIN X_TRANS.CUSTOMER_PHONE_CURRENT CPC_BP
ON TD.INVOLVED_PARTY_ID = CPC_BP.INVOLVED_PARTY_ID
AND CPC_BP.IP_TEL_ADDRESS_RLN_TYPE_CODE = 'BPNR'
LEFT OUTER JOIN X_TRANS.CUSTOMER_PHONE_CURRENT CPC_HP
ON TD.INVOLVED_PARTY_ID = CPC_HP.INVOLVED_PARTY_ID
AND CPC_HP.IP_TEL_ADDRESS_RLN_TYPE_CODE = 'HPNR'
LEFT OUTER JOIN X_TRANS.ORGANIZATION_CURRENT OC
ON TD.INVOLVED_PARTY_ID = OC.INVOLVED_PARTY_ID
LEFT OUTER JOIN X_TRANS.CUSTOMER_ADDRESS_CURRENT CAC_RA
ON TD.INVOLVED_PARTY_ID = CAC_RA.INVOLVED_PARTY_ID
AND CAC_RA.IP_ADDRESS_RLTNP_TYPE_CODE = '10'
LEFT OUTER JOIN X_TRANS.CUSTOMER_WEB_ADDRESS_CURRENT CWAC_BW
ON TD.INVOLVED_PARTY_ID = CWAC_BW.INVOLVED_PARTY_ID
AND CWAC_BW.IP_WEB_ADDRESS_RLN_CODE = 'BW'
LEFT OUTER JOIN X_TRANS.CUSTOMER_ADDRESS_CURRENT CAC_PA
ON TD.INVOLVED_PARTY_ID = CAC_PA.INVOLVED_PARTY_ID
AND CAC_PA.IP_ADDRESS_RLTNP_TYPE_CODE = '1'
LEFT OUTER JOIN X_TRANS.CUSTOMER_ADDRESS_CURRENT CAC_EA
ON TD.INVOLVED_PARTY_ID = CAC_EA.INVOLVED_PARTY_ID
AND CAC_EA.IP_ADDRESS_RLTNP_TYPE_CODE = '70'
WHERE TD.INFORMATION_DATE = CURRENT_TIMESTAMP;
Thanks for you patience to go through the code.
Regards,
Amit
There's no way to "tune" this query, approach your DBA to open an incident with Teradata support. You found a bug, don't try to fix it on your own.
And please follow the advice and don't submit it again (a 3610 is recorded in the logs including the user who caused it). There were enhancement requests (by DBAs) like "change the error message to Hey stupid, I just told you not to submit again when it's submitted a 2nd time and block the user the 3rd time"
Related
I have a query against a UDF where I want to allow the user to pass in either ALL or a specific EType.
If they pass in ALL, I want to accept all ETypes where it is not null.
I have searched thru SO for examples and not seem to meet my particular situation.
Where am I going wrong?
Declare
#company varchar(4),
#charge_cov bit,
#EType varchar(8);
set #company = '123'
set #charge_cov =1
set #EType = 'ALL'
select e.emp_id,
dbo.format_emp_number(pd.EN) as EN,
dbo.format_emp_number(pd.MEN) as MEN,
pd.EType
from dbo.employee_payroll_data(NULL) pd
inner join employee e on (e.emp_id=pd.emp_id)
where pd.EType = case when #EType='ALL' then pd.EType
else #EType ) END
and pd.EType is not null
and e.emp_number is not null
and e.charge_cov = 1
and lc.pr_co_code = #company
Try below code:
WHERE (((1 = (CASE WHEN #EType = 'ALL' THEN 1 ELSE 0 END)))
OR ((pd.Etype = (CASE WHEN #EType <> 'ALL' THEN #EType ELSE '' END))))
AND pd.Etype IS NOT NULL
We managed awhile back to cobble some really complex (to us) database queries that pull some dynamic meta_values in with the general Post info in WordPress so that the result was a nice, full list of key=>value pairs. It's worked great for years but now we've switched to MariaDB and it's no longer ordering properly and I'm not sure why. See below for one of the big, long examples or screenshot at https://screencast.com/t/mFILYpWf for a bit more formatting.
Any ideas on how I can get it to order by menu_order first, last_name then first_name?
Thanks as always!!
SELECT *
FROM
(
SELECT wp_posts.ID, wp_posts.menu_order, wp_posts.post_title,
wp_posts.post_name,
MAX(CASE WHEN wp_postmeta.meta_key = 'lawyer_job_title'
THEN wp_postmeta.meta_value END ) AS 'job_title',
MAX(CASE WHEN wp_postmeta.meta_key = 'lawyer_prefix'
THEN wp_postmeta.meta_value END ) AS 'prefix',
MAX(CASE WHEN wp_postmeta.meta_key = 'lawyer_first_name'
THEN wp_postmeta.meta_value END ) AS 'first_name',
MAX(CASE WHEN wp_postmeta.meta_key = 'lawyer_middle_name'
THEN wp_postmeta.meta_value END ) AS 'middle_name',
MAX(CASE WHEN wp_postmeta.meta_key = 'lawyer_last_name'
THEN wp_postmeta.meta_value END ) AS 'last_name',
MAX(CASE WHEN wp_postmeta.meta_key = 'lawyer_suffix'
THEN wp_postmeta.meta_value END ) AS 'suffix',
MAX(CASE WHEN wp_postmeta.meta_key = 'lawyer_languages'
THEN wp_postmeta.meta_value END ) AS 'languages',
MAX(CASE WHEN wp_postmeta.meta_key = 'lawyer_email'
THEN wp_postmeta.meta_value END ) AS 'email',
MAX(CASE WHEN wp_postmeta.meta_key = 'lawyer_phone'
THEN wp_postmeta.meta_value END ) AS 'phone',
MAX( CASE WHEN wp_postmeta.meta_key = 'lawyer_offices' THEN wp_postmeta.meta_value END ) AS 'offices',MAX( CASE WHEN wp_postmeta.meta_key = 'lawyer_linkedin' THEN wp_postmeta.meta_value END ) AS 'linkedin',MAX( CASE WHEN wp_postmeta.meta_key = 'lawyer_biography' THEN wp_postmeta.meta_value END ) AS 'biography',MAX( CASE WHEN wp_postmeta.meta_key = 'lawyer_bio_field_credentials' THEN wp_postmeta.meta_value END ) AS 'bio_field_credentials',MAX( CASE WHEN wp_postmeta.meta_key = 'lawyer_bio_field_affiliations' THEN wp_postmeta.meta_value END ) AS 'bio_field_affiliations',MAX( CASE WHEN wp_postmeta.meta_key = 'lawyer_bio_field_accolades' THEN wp_postmeta.meta_value END ) AS 'bio_field_accolades',MAX( CASE WHEN wp_postmeta.meta_key = 'lawyer_bio_field_notable_decisions' THEN wp_postmeta.meta_value END ) AS 'bio_field_notable_decisions',MAX( CASE WHEN wp_postmeta.meta_key = 'lawyer_bio_field_education_admissions' THEN wp_postmeta.meta_value END ) AS 'bio_field_education_admissions',MAX( CASE WHEN wp_postmeta.meta_key = 'lawyer_bio_image' THEN wp_postmeta.meta_value END ) AS 'bio_image',MAX( CASE WHEN wp_postmeta.meta_key = 'lawyer_directory_image' THEN wp_postmeta.meta_value END ) AS 'directory_image',MAX( CASE WHEN wp_postmeta.meta_key = 'lawyer_pdf_image' THEN wp_postmeta.meta_value END ) AS 'pdf_image',MAX( CASE WHEN wp_postmeta.meta_key = 'lawyer_practices' THEN wp_postmeta.meta_value END ) AS 'practices',MAX( CASE WHEN wp_postmeta.meta_key = 'lawyer_related_posts' THEN wp_postmeta.meta_value END ) AS 'related_posts',MAX( CASE WHEN wp_postmeta.meta_key = 'lawyer_other_news' THEN wp_postmeta.meta_value END ) AS 'other_news',MAX( CASE WHEN wp_postmeta.meta_key = 'lawyer_related_staff' THEN wp_postmeta.meta_value END ) AS 'related_staff', concat( 'http://wiedner.localhost/lawyer/', wp_posts.post_name, '/' ) AS 'permalink' FROM wp_posts LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE wp_posts.post_status = 'publish' AND wp_posts.post_type = 'lawyer'
GROUP BY wp_posts.ID
ORDER BY menu_order asc, last_name asc, first_name asc
) AS t
WHERE 1=1
Simplify it by getting rid of the outer SELECT!
The reason is that a 'derived' table (your subquery) has no order. (This has long been in Standard SQL, but only recently have MariaDB, and later MySQL, taken advantage of it.) That is, the execution is justified to get rid of your carefully written ORDER BY.
But, by stopping with the inner query; it is obligated to honor the ORDER BY.
MariaDB may have a different mode set. Try this, and see here:
SET GLOBAL sql_mode=(SELECT REPLACE(##sql_mode,'ONLY_FULL_GROUP_BY',));
Also this may be a duplicate, see this related question.
//i had shared a piece of code where i am getting the error.
here i want to pass the date range and get the data from the query in my data frame
output$DateRange <- renderText(
if(USER$Logged==TRUE){
//getting the input date ranges from here
validate(
need(as.character(Sys.Date()) >= input$dates[1],
"Start Date should be less than or equal to Current Date"
)
)
validate(
need(input$dates[2] <= as.character(Sys.Date()) && input$dates[2] >= input$dates[1], "End Date should be greater than Start date and less than Current Date"
))
})
//i am passing date range from here in my query but i am getting a error while passing datesetFirst and datesetSecond
datesetFirst <- reactive(input$dates[1])
datesetSecond <- reactive(input$dates[2])
if (!is.null(datesetFirst) && !is.null(datesetSecond))
{
// this is the query i want to execute after passing the date range from here i want to get the data on the basis of input range
resultset =paste("SELECT SET2.AREA_NAME,SET2.PROD_NM,
SET2.TherapeuticClass,set2.TOTAL,
ROUND(((set2.TOTAL/SET3.TOTAL)*100),2) as SHARE
FROM (select retail_store_area_wise.area_name AS AREA_NAME,
set1.PROD_NM AS PROD_NM,sum(set1.TOTAL) AS TOTAL,
set1.TH_CLASS_1 AS TH_1,
set1.TH_CLASS_2 AS TH_2,
set1.TH_CLASS_3 AS TH_3,
set1.TH_CLASS_4 AS TH_4,
CONCAT(CONCAT(CONCAT(CONCAT( set1.TH_CLASS_1, ','),set1.TH_CLASS_2),','),CONCAT(CONCAT( set1.TH_CLASS_3, ','),set1.TH_CLASS_4) ) as TherapeuticClass
from
(select
retail_store_prod.TH_CLASS_4 as TH_CLASS_4,
retail_store_prod.TH_CLASS_3 as TH_CLASS_3,
retail_store_prod.TH_CLASS_2 as TH_CLASS_2,
retail_store_prod.TH_CLASS_1 as TH_CLASS_1,
retail_store_prod.store_id as store_id ,
retail_store.str_nm,
retail_Str_sales_detail.prod_nm as PROD_NM,
round(sum (retail_Str_sales_detail.total),2) AS TOTAL
from
retail_str_sales_detail ,
retail_store_prod,retail_store
where
retail_store_prod.prod_nm = retail_str_sales_detail.prod_nm and
retail_store_prod.store_id=retail_str_sales_detail.store_id and
retail_store.store_id = retail_store_prod.store_id AND
retail_str_sales_detail.SALE_DATE BETWEEN //while passing the date range here i am getting the error**'",datesetFirst,"'** AND **'",datesetSecond,"'**
AND retail_store_prod.TH_CLASS_4 != 'NULL'
AND retail_store_prod.TH_CLASS_3 != 'NULL'
AND retail_store_prod.TH_CLASS_2 != 'NULL'
AND retail_store_prod.TH_CLASS_1 != 'NULL'
AND retail_store_prod.TH_CLASS_4 != ''
AND retail_store_prod.TH_CLASS_3 != ''
AND retail_store_prod.TH_CLASS_2 != ''
AND retail_store_prod.TH_CLASS_1 != ''
GROUP BY
retail_store_prod.TH_CLASS_4 ,
retail_store_prod.TH_CLASS_3 ,
retail_store_prod.TH_CLASS_2 ,
retail_store_prod.TH_CLASS_1 ,
retail_Str_sales_detail.prod_nm ,retail_store.str_nm,
retail_store_prod.store_id
order by retail_Str_sales_detail.prod_nm,
retail_store_prod.TH_CLASS_4 ,
retail_store_prod.TH_CLASS_3 ,
retail_store_prod.TH_CLASS_2 ,
retail_store_prod.TH_CLASS_1 ,retail_store.str_nm,
round(sum (retail_Str_sales_detail.total),2) desc) as set1, retail_store_area_wise
where set1.store_id = retail_store_area_wise.store_id
group by set1.PROD_NM,
set1.TH_CLASS_1,
set1.TH_CLASS_2,
set1.TH_CLASS_3,
set1.TH_CLASS_4,
retail_store_area_wise.area_name,CONCAT(CONCAT(CONCAT(CONCAT( set1.TH_CLASS_1, ','),set1.TH_CLASS_2),','),CONCAT(CONCAT( set1.TH_CLASS_3, ','),set1.TH_CLASS_4) )
order by retail_store_area_wise.area_name,set1.PROD_NM) as SET2
FULL OUTER JOIN
(select retail_store_area_wise.area_name AS AREA_NAME,sum(set1.TOTAL) AS TOTAL,
set1.TH_CLASS_1 AS TH_1,
set1.TH_CLASS_2 AS TH_2,
set1.TH_CLASS_3 AS TH_3,
set1.TH_CLASS_4 AS TH_4,
CONCAT(CONCAT(CONCAT(CONCAT( set1.TH_CLASS_1, ','),set1.TH_CLASS_2),','),CONCAT(CONCAT( set1.TH_CLASS_3, ','),set1.TH_CLASS_4) ) as TherapeuticClass
from
(select
retail_store_prod.TH_CLASS_4 as TH_CLASS_4,
retail_store_prod.TH_CLASS_3 as TH_CLASS_3,
retail_store_prod.TH_CLASS_2 as TH_CLASS_2,
retail_store_prod.TH_CLASS_1 as TH_CLASS_1,
retail_store_prod.store_id as store_id ,
retail_store.str_nm,
retail_Str_sales_detail.prod_nm as PROD_NM,
round(sum (retail_Str_sales_detail.total),2) AS TOTAL
from
retail_str_sales_detail ,
retail_store_prod,retail_store
where
retail_store_prod.prod_nm = retail_str_sales_detail.prod_nm and
retail_store_prod.store_id=retail_str_sales_detail.store_id and
retail_store.store_id = retail_store_prod.store_id AND
retail_str_sales_detail.SALE_DATE BETWEEN '",datesetFirst,"' AND '",datesetSecond,"'
AND retail_store_prod.TH_CLASS_4 != 'NULL'
AND retail_store_prod.TH_CLASS_3 != 'NULL'
AND retail_store_prod.TH_CLASS_2 != 'NULL'
AND retail_store_prod.TH_CLASS_1 != 'NULL'
AND retail_store_prod.TH_CLASS_4 != ''
AND retail_store_prod.TH_CLASS_3 != ''
AND retail_store_prod.TH_CLASS_2 != ''
AND retail_store_prod.TH_CLASS_1 != ''
GROUP BY
retail_store_prod.TH_CLASS_4 ,
retail_store_prod.TH_CLASS_3 ,
retail_store_prod.TH_CLASS_2 ,
retail_store_prod.TH_CLASS_1 ,
retail_Str_sales_detail.prod_nm ,retail_store.str_nm,
retail_store_prod.store_id
order by retail_Str_sales_detail.prod_nm,
retail_store_prod.TH_CLASS_4 ,
retail_store_prod.TH_CLASS_3 ,
retail_store_prod.TH_CLASS_2 ,
retail_store_prod.TH_CLASS_1 ,retail_store.str_nm,
round(sum (retail_Str_sales_detail.total),2) desc) as set1, retail_store_area_wise
where set1.store_id = retail_store_area_wise.store_id group by
set1.TH_CLASS_1,
set1.TH_CLASS_2,
set1.TH_CLASS_3,
set1.TH_CLASS_4,
retail_store_area_wise.area_name,
CONCAT(CONCAT(CONCAT(CONCAT( set1.TH_CLASS_1, ','),set1.TH_CLASS_2),','),CONCAT(CONCAT( set1.TH_CLASS_3, ','),set1.TH_CLASS_4) )
order by retail_store_area_wise.area_name) AS SET3
ON SET3.AREA_NAME= SET2.AREA_NAME AND
SET3.TH_1= SET2.TH_1 AND
SET3.TH_2 = SET2.TH_2 AND
SET3.TH_3 = SET2.TH_3 AND
SET3.TH_4 = SET2.TH_4");
querytherapeutic1= reactive({dbGetQuery(conn,resultset)})
biztherapeuticproduct1= data.frame(
Area= querytherapeutic1$AREA_NAME,
THERAPEUTIC_CLASS= querytherapeutic1$THERAPEUTICCLASS,
Market_Share= as.numeric(as.character(querytherapeutic1$SHARE)),
Product= querytherapeutic1$PROD_NM,
Total = as.numeric(as.character(querytherapeutic1$TOTAL)),
stringsAsFactors = FALSE
)}
Your error message ist from this part of the code
datesetFirst <- reactive(input$dates[1])
datesetSecond <- reactive(input$dates[2])
if (!is.null(datesetFirst) && !is.null(datesetSecond))
reactive returns a function not a value so you need to change your code to this
datesetFirst <- reactive(input$dates[1])
datesetSecond <- reactive(input$dates[2])
if (!is.null(datesetFirst()) && !is.null(datesetSecond()))
and of course in the query aswell
"retail_str_sales_detail.SALE_DATE BETWEEN '",datesetFirst(),"' AND '",datesetSecond(),"'
I have this query in my application
SELECT
/*+ parallel (4) */
a.orgkey AS cifid,
a.strfield19 AS old_cif_id,
a.cust_first_name,
a.cust_middle_name,
a.cust_last_name,
a.primary_sol_id AS sol_id,
(
SELECT lang.localetext
FROM crmuser.categories cat,
crmuser.category_lang lang
WHERE cat.categoryid=lang.categoryid
AND cat.categorytype= 'PERSONSALUTATION'
AND cat.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND lang.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND cat.value= a.salutation) AS saluatation,
a.segmentation_class AS segmentation_class,
CASE
WHEN corp_id IS NULL THEN
(
SELECT lang.localetext
FROM crmuser.categories cat,
crmuser.category_lang lang
WHERE cat.categoryid=lang.categoryid
AND cat.categorytype= 'SEGMENTATION_CLASS'
AND cat.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND lang.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND cat.value= a.segmentation_class)
ELSE
(
SELECT lang.localetext
FROM crmuser.categories cat,
crmuser.category_lang lang
WHERE cat.categoryid=lang.categoryid
AND cat.categorytype= 'CORP_SEGMENTATION_CLASS'
AND cat.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND lang.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND cat.value= a.segmentation_class)
END AS segmentation_desc,
a.subsegment AS subsegment,
CASE
WHEN corp_id IS NULL THEN
(
SELECT lang.localetext
FROM crmuser.categories cat,
crmuser.category_lang lang
WHERE cat.categoryid=lang.categoryid
AND cat.categorytype= 'SUB_SEGMENT'
AND cat.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND lang.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND cat.value= a.subsegment)
ELSE
(
SELECT lang.localetext
FROM crmuser.categories cat,
crmuser.category_lang lang
WHERE cat.categoryid=lang.categoryid
AND cat.categorytype= 'CORP_SUB_SEGMENT'
AND cat.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND lang.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND cat.value= a.subsegment)
END AS subsegment_desc,
CASE
WHEN a.corp_id IS NULL THEN a.strfield10
ELSE c.struserfield4
END AS reserve_bank_code,
CASE
WHEN a.corp_id IS NULL THEN a.strfield11
ELSE c.struserfield5
END AS form50_code,
a.sector AS pri_sic_code,
a.subsector AS sec_sic_code,
CASE
WHEN a.corp_id IS NULL THEN a.struserfield3
ELSE c.struserfield3
END AS kyc_indicator,
a.defaultaddresstype AS defaultaddresstype,
b.address_line1,
b.address_line2,
b.address_line3,
CASE
WHEN a.corp_id IS NULL THEN
(
SELECT (ad.address_line1
||' '
||ad.address_line2
||' '
||ad.address_line3)
FROM crmuser.address ad
WHERE a.orgkey=ad.orgkey
AND ad. preferredaddress='Y'
AND
(
SELECT migration_date
FROM migadm.migr_det) BETWEEN ad.start_date AND ad.end_date)
ELSE
(
SELECT (ad.address_line1
||' '
||ad.address_line2
||' '
||ad.address_line3)
FROM crmuser.address ad
WHERE a.orgkey=ad.orgkey
AND ad.preferredaddress='Y' and
(
SELECT migration_date
FROM migadm.migr_det) BETWEEN ad.start_date AND ad.end_date)
END AS postal_adress,
b.zip AS postal_code,
a.gender AS gender,
a.cust_dob AS date_of_birth,
(
SELECT p.email
FROM crmuser.phoneemail p
WHERE p.orgkey = a.orgkey
AND p.preferredflag='Y'
AND phoneoremail='EMAIL'
AND ROWNUM =1) email_id,
(
SELECT p.phonenocountrycode
FROM crmuser.phoneemail p
WHERE p.orgkey = a.orgkey
AND p.preferredflag='Y'
AND phoneoremail='PHONE'
AND ROWNUM =1) AS phone_cntry_code,
(
SELECT p.phonenocitycode
FROM crmuser.phoneemail p
WHERE p.orgkey = a.orgkey
AND p.preferredflag='Y'
AND phoneoremail='PHONE'
AND ROWNUM =1) AS phone_city_code,
(
SELECT '+'
|| p.phonenocountrycode
|| '('
|| p.phonenocitycode
|| ')'
|| p.phonenolocalcode
FROM crmuser.phoneemail p
WHERE p.orgkey = a.orgkey
AND p.preferredflag = 'Y'
AND phoneoremail='PHONE') phone_no,
--CASE WHEN (SELECT COUNT(1) FROM crmuser.miscellaneousinfo m WHERE a.orgkey=m.orgkey and type = 'CURRENCY') = 1 THEN (SELECT strtext10 FROM crmuser.miscellaneousinfo m WHERE a.orgkey=m.orgkey and type = 'CURRENCY')
-- WHEN (SELECT COUNT(1) FROM crmuser.corpmiscellaneousinfo m WHERE a.orgkey=m.orgkey and type = 'CURRENCY') = 1 THEN (SELECT str1 FROM crmuser.corpmiscellaneousinfo m WHERE a.orgkey=m.orgkey and type = 'CURRENCY')
-- ELSE
migadm.getcurrencies(a.orgkey)
--END
AS crncy_code,
CASE
WHEN a.corp_id IS NULL THEN a.struserfield15
ELSE c.struserfield6
END AS wht_indicator,
a.cust_swift_code_desc AS cust_swift_code_desc,
customernreflg AS customernreflg,
(
SELECT employerid
FROM crmuser.miscellaneousinfo s
WHERE s.orgkey = a.orgkey
AND TYPE ='CURRENT_EMPLOYMENT') AS group_number,
(
SELECT strtext4
FROM crmuser.miscellaneousinfo s
WHERE s.orgkey = a.orgkey
AND TYPE ='CURRENT_EMPLOYMENT' ) AS employment_details,
--(select EMPLOYERSNAME from crmuser.DEMOGRAPHIC s where s.orgkey = a.orgkey ) AS employment_details,
(
SELECT employeeid
FROM crmuser.miscellaneousinfo s
WHERE s.orgkey = a.orgkey
AND TYPE ='CURRENT_EMPLOYMENT' ) AS employeeid,
--(select EMPLOYERID from crmuser.MISCELLANEOUSINFO s where s.orgkey = a.orgkey ) AS employerid,
a.manager AS manager,
CASE
WHEN a.corp_id IS NULL THEN d.annual_salary_income
ELSE c.average_annualincome
END AS annual_income,
c.registration_number
FROM crmuser.corporate c
right join crmuser.address b
ON b.orgkey=c.corp_key
right join crmuser.accounts a
ON b.orgkey=a.orgkey
left join crmuser.demographic d
ON a.orgkey=d.orgkey
WHERE a.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND a.entity_cre_flag = 'Y'
AND b.preferredaddress = 'Y'
It takes more than 20 minutes to give results. Can someone please help me in tuning this query. I don't have any idea about sql.
I can give the explain plan needed but I don't know how to copy here the 111 rows from plan table
SubQuery pulling in the same record in the "ON_ORDER" column. I want the query to pull in the ON_ORDER qty per Item. Can someone please show me what I am not doing right? I have been on this for quite awhile.
SELECT
N.SITEID,
C.LOCATION,
(I.EX2AREARESP||I.EX2STDSTS||I.EX2APPTYPE) AS STD,
I.ITEMNUM,
I.COMMODITY,
I.COMMODITYGROUP,
I.DESCRIPTION,
I.ISSUEUNIT,
C.AVGCOST,
SUM(NVL(B.CURBAL,0)) AS CURBAL,
NVL(SUM(D.SHIPPEDQTY),0) AS IN_TRANSIT,
(
SELECT
SUM(PL.ORDERQTY - NVL(PL.RECEIVEDQTY,0))
FROM MSCRADS.PO P,
MSCRADS.POLINE PL,
MXRADS.ITEM I
WHERE P.PONUM = PL.PONUM
AND PL.LINETYPE = 'ITEM'
AND P.RECEIPTS <> 'COMPLETE'
AND PL.ITEMNUM = I.ITEMNUM
AND P.ORDERDATE >= TO_DATE('2014/05/26','YYYY/MM/DD')
AND PL.RECEIPTSCOMPLETE = '0'
AND P.INTERNAL = '0'
AND PL.ISSUE = '0'
AND P.STATUS NOT IN ('COMPLETE','CLOSE','CAN')
AND P.SITEID <> 'MS'
AND P.REVISIONNUM = PL.REVISIONNUM
AND (P.HISTORYFLAG = '0' OR (P.HISTORYFLAG = '1'
AND P.STATUS = 'CLOSE' AND PL.RECEIVEDQTY > '0'))
AND NOT (P.STATUS = 'COMPLETE'
AND (PL.RECEIVEDQTY = '0' OR PL.RECEIVEDQTY IS NULL))
) AS "ON_ORDER",
NVL(SUM(CASE WHEN D.RESTYPE = 'APSOFT' THEN D.RESERVEDQTY
ELSE NULL END),0) AS "ALLOCATED",
NVL(SUM(CASE WHEN D.RESTYPE = 'APHARD' THEN D.RESERVEDQTY
ELSE NULL END),0) AS "RESERVE",
N.MINLEVEL AS ROP,
N.ORDERQTY AS EOQ,
N.DELIVERYTIME AS LEADTIME,
NVL(N.SSTOCK,0) "SAFETY STOCK",
CASE N.REORDER WHEN 1 THEN 'AUTO_RE-ORDER'
WHEN 0 THEN 'MANUAL_RE-ORDER'
ELSE ' '
END AS "REORDER PROCESS",
N.STATUS "INVENTORY STATUS"
FROM MXRADS.INVENTORY N
LEFT OUTER JOIN
MXRADS.ITEM I
ON I.ITEMNUM = N.ITEMNUM
LEFT OUTER JOIN
MSCRADS.INVCOST C
ON N.ITEMNUM = C.ITEMNUM
AND N.LOCATION = C.LOCATION
LEFT OUTER JOIN
MSCRADS.INVBALANCES B
ON N.ITEMNUM = B.ITEMNUM
AND N.LOCATION = B.LOCATION
LEFT OUTER JOIN
MSCRADS.INVRESERVE D
ON N.ITEMNUM = D.ITEMNUM
AND N.LOCATION = D.LOCATION
WHERE N.SITEID <> 'MS'
AND N.LOCATION = '&WHSE'
AND N.STATUS = 'ACTIVE'
--AND N.ITEMNUM = '505611'
GROUP BY
N.SITEID,
C.LOCATION,
(I.EX2AREARESP||I.EX2STDSTS||I.EX2APPTYPE),
I.ITEMNUM,
I.COMMODITY,
I.COMMODITYGROUP,
I.DESCRIPTION,
I.ISSUEUNIT,
C.AVGCOST,
N.MINLEVEL,
N.ORDERQTY,
N.DELIVERYTIME,
N.SSTOCK,
N.REORDER,
N.STATUS
ORDER BY 4