Postgresql: Error missing FROM-clause entry for table - postgresql

I have a query and I keep getting this a 'missing FROM-clase entry for table e, rx.rootentityid = rh.entityid1 AND rh.schoolid = e.schoolid'.
can anyone see the error in my code. My postgresql knowledge is very limited.
SELECT
eh.entityid1, eh.entityname1, eh.entityid2, eh.entityname2,
eh.entityid3, eh.entityname3, eh.entityid4, eh.entityname4,
eh.entityid5, eh.entityname5, eh.entityid6, eh.entityname6,
eh.entityid7, eh.entityname7, eh.schoolentityid, eh.schoolid,
eh.emiscode, eh.schoolname, rh.entityid1 AS reportentityid1,
rh.entityname1 AS reportentityname1, rh.entityid2 AS reportentityid2,
rh.entityname2 AS reportentityname2
FROM dbo.vwentityhierarchyname
JOIN dbo.entity AS eh
ON vwentityhierarchyname.entityid1 = eh.entityid AND eh.entitytypeid = 1
CROSS JOIN (SELECT
hd.rootentityid
FROM dbo.hierarchydefinition AS hd
JOIN dbo.entity AS e
ON hd.rootentityid = e.entityid
WHERE hd.relatedrootentityid = e.entityid AND hd.entitytypeid = 7 AND LOWER(e.name) SIMILAR TO LOWER('%Report Regions%')) AS rx
LEFT OUTER JOIN dbo.vwentityhierarchyname AS rh
ON rx.rootentityid = rh.entityid1 AND rh.schoolid = e.schoolid
WHERE eh.schoolid = par_SchoolID
ORDER BY eh.entityid1 DESC NULLS FIRST
LIMIT 1;
Thanks

Related

The multi-part identifier could not be bound - SQL Server 2016

SELECT clm.CLCL_PAYEE_PR_ID, clm.SBSB_CK, clm.CLCL_ID, clm.clcl_id_adj_to,clm.clcl_id_adj_from, clm.CLCL_PAID_DT
FROM ODW.DW.fac_cmc_clcl_claim CLM
INNER JOIN ODW.DW.fac_cmc_meme_member MEME ON MEME.meme_ck = CLM.meme_ck
INNER JOIN ODW.DW.fac_cmc_mepe_prcs_elig MEPE ON MEPE.meme_ck = MEME.meme_ck
INNER JOIN ODW.DW.fac_cmc_mepr_prim_prov MEPR ON MEPE.meme_ck = MEPR.meme_ck AND CLM.clcl_prpr_id_pcp = MEPR.prpr_id
INNER JOIN ODW.DW.fac_cmc_sbsb_subsc SBSB ON MEME.sbsb_ck = SBSB.sbsb_ck
INNER JOIN ODW.DW.fac_cmc_prpr_prov PROV ON MEPR.prpr_id = PROV.prpr_id AND PROV.prpr_mctr_prty = 'RISK'
INNER JOIN ODW.DW.fac_cmc_prer_relation PRER ON PRER.prpr_id = MEPR.prpr_id
INNER JOIN ODW.DW.fac_cmc_plds_plan_desc PLDS ON MEPE.cspi_id = PLDS.cspi_id
INNER JOIN ODW.DW.fac_cmc_pdds_prod_desc PDDS ON MEPE.pdpd_id = PDDS.pdpd_id
WHERE CLM.clcl_paid_dt BETWEEN '2019-12-24 00:00:00.000' AND '2019-12-30 23:59:59.997'
AND CLM.clcl_cur_sts = '02'
AND CLM.clcl_cl_type = 'M'
AND CLM.clcl_cl_sub_type = 'H'
AND CLM.grgr_ck IN (46)
AND MEPR.grgr_ck IN (46)
AND MEPE.grgr_ck IN (46)
AND MEPE.mepe_elig_ind = 'Y'
AND CLM.clcl_low_svc_dt BETWEEN MEPE.mepe_eff_dt AND MEPE.mepe_term_dt
AND CLM.clcl_low_svc_dt BETWEEN MEPR.mepr_eff_dt AND MEPR.mepr_term_dt
AND SBSB.grgr_ck IN (46)
AND PRER.prer_prpr_entity = 'I'
AND PRER.prer_prpr_id IN ('64456546')
AND (PLDS.plds_desc LIKE '%risk%' OR PDDS.pdds_desc LIKE '%risk%');
This query runs in PROD with different variables which substitute the value of the hard coded values. It runs around 100 times per day in PROD and on some days some of the runs fail due to this error:
The multi-part identifier "PDDS.pdds_desc" could not be bound
Please note that all the joins are being done on views.
When I re-run the failed process, it succeeds the second time with no changes to the underlying query.
Can anyone suggest what could be the issue. Also, any performance optimization suggestions for this query query will be appreciated.
Thanks!

Magento2 - debug SQL errors

I am getting errors like
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e.name' in 'field list', query was: SELECT `e`.*, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price`, `cat_index`.`position` AS `cat_index_position`, `e`.`name`, `e`.`image`, `e`.`small_image`, `e`.`thumbnail`, `e`.`name`, `e`.`short_description`, `e`.`price`, `e`.`special_price`, `e`.`special_from_date`, `e`.`special_to_date`, `e`.`image`, `e`.`small_image`, `e`.`thumbnail`, `e`.`news_from_date`, `e`.`news_to_date`, `e`.`required_options`, `e`.`image_label`, `e`.`small_image_label`, `e`.`thumbnail_label`, `e`.`url_key`, `e`.`msrp`, `e`.`msrp_display_actual_price_type`, `e`.`price_type`, `e`.`weight_type`, `e`.`price_view`, `e`.`links_purchased_separately`, `e`.`links_exist`, `e`.`swatch_image`, `e`.`tax_class_id`, `e`.`cross_tier_id`, `e`.`cross_tier_id_value`, `e`.`open_amount_max`, `e`.`open_amount_min`, `e`.`package_size`, `e`.`sw_featured`, SUM(soi.qty_ordered) AS `ordered_qty`, `order`.`state`, `stock_status_index`.`stock_status` AS `is_salable` FROM `catalog_product_entity` AS `e`
INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0
INNER JOIN `catalog_category_product_index_store1` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.category_id=2
LEFT JOIN `sales_order_item` AS `soi` ON soi.product_id = e.entity_id
INNER JOIN `sales_order` AS `order` ON order.entity_id = soi.order_id
LEFT JOIN `cataloginventory_stock_status` AS `stock_status_index` ON e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1 WHERE (order.state <> 'canceled' and soi.parent_item_id IS NULL AND soi.product_id IS NOT NULL) GROUP BY `soi`.`product_id` ORDER BY `ordered_qty` DESC
LIMIT 8
In magento logs i do not see information which class produced this error.
How can i found out what class/module is responsible for this query?
you can run bin / magento dev: query-log: enable
to see all sql queries

change query from postgresql into oracle

how change this query from postgresql into oracle?
SELECT tbmm.tbmm_id,
tbmm.tbmm_email AS seller_mail,
'FB' AS seller_type,
concat(tbmm.tbmm_firstname, COALESCE(tbmm.tbmm_middlename),
COALESCE(tbmm.tbmm_lastname)) AS seller_owner_name,
tbmss.tbmss_name AS seller_store_name,
tbmss.tbmss_description AS seller_description,
tbmss.tbmss_phone AS seller_phone,
btrim(concat(COALESCE(tbmma.tbmma_addr1), COALESCE(tbmma.tbmma_addr2,
tbmma.tbmma_addr1), COALESCE(tbmma.tbmma_addr3, tbmma.tbmma_addr1),
COALESCE(tbmkc.tbmkct_nama), COALESCE(tbmkl.tbmkl_nama),
COALESCE(tbmma.tbmma_postcode, '0') AS seller_store_address,
tbmb.tbmb_name AS bank_name,
concat(tbmb.tbmb_name, COALESCE(tbmsd.tbmsd_bank_account_branch) AS
bank_desc,
tbmsd.tbmsd_bank_account_no AS bank_account_no,
tbmsd.tbmsd_bank_account_name AS bank_account_name,
tbmsd.tbmsd_no_id AS seller_id_card,
'F' AS flag_alfamind,
0 AS commision,
tbmm.tbmm_mage_entity_id,
tbmm.tbmm_update_date AS member_update_date,
tbmss.tbmss_update_date AS store_update_date,
tbmsd.tbmsd_update_date AS document_update_date,
tbmma.tbmma_update_date AS address_update_date
FROM coreapp.tb_master_member tbmm
JOIN coreapp.tb_master_seller_store tbmss ON tbmm.tbmm_id =
tbmss.tbmm_id
JOIN coreapp.tb_master_seller_document tbmsd ON tbmsd.tbmm_id =
tbmm.tbmm_id
JOIN coreapp.tb_master_bank tbmb ON tbmb.tbmb_id = tbmsd.tbmb_id
JOIN coreapp.tb_master_member_group tbmg ON tbmg.tbmm_id = tbmm.tbmm_id
LEFT JOIN coreapp.tb_master_member_address tbmma ON tbmma.tbmm_id =
tbmm.tbmm_id AND tbmma.tbmma_address_type = 140 AND tbmma.tbmma_status = 23
LEFT JOIN coreapp.tb_master_kecamatan tbmkc ON
tbmkc.tbmkct_kecamatan_id = tbmma.tbmkct_kecamatan_id
LEFT JOIN coreapp.tb_master_kelurahan tbmkl ON tbmkl.tbmkl_kelurahan_id
= tbmma.tbmkl_kelurahan_id
WHERE tbmg.tbmg_id = 4;
i have try to query on my sql developer but something error with query
now I'm just try until one day and still can't run

Schema error from postgresql update statement

I have a POSTGRESQL update statement that I'm trying to rewrite with explicit joins and needing some help whereby the NESTED select statement alias is recognized to execute the outer UPDATE statement. Not sure why the "se" alias for the nested select is NOT recognized. I know I must be missing something basic.
Any help/direction would be appreciated. Thanks.
Error I'm getting:
ERROR: schema "se" does not exist
********** Error **********
ERROR: schema "se" does not exist
SQL state: 3F000
Here is my code:
UPDATE students
SET custom_400011449 = CAST(cfso1.label as integer)+1,
custom_400011770 = 761 --'2016-2017'
FROM (
SELECT se2.student_id, cfso1.id, cfso1.label
FROM students s
INNER JOIN student_enrollment se2
ON s.student_id = se2.student_id
INNER JOIN school_gradelevels sg
ON se2.grade_id = sg.id
INNER JOIN custom_field_log_entries sle
ON se2.student_id = sle.source_id
LEFT JOIN custom_field_select_options cfso1
ON s.custom_400011449 = cfso1.id
LEFT JOIN custom_field_select_options cfso2
ON s.custom_400011770 = cfso2.id
LEFT JOIN custom_field_select_options cfso3
ON sle.log_field4::INT = cfso3.id
WHERE se2.syear =2016
AND s.custom_400011449 IS NOT NULL
AND s.custom_400011898 IS NULL
AND s.custom_400011899 IS NULL
AND sle.field_id = 15 --400010549
AND sle.log_field2 IS NULL
AND cfso2.label = '2015-2016'
AND cfso3.label IN ('LE', 'NL-F', 'NL-S')
AND sg.short_name BETWEEN '01' AND '12'
AND (
SELECT COUNT(school_date)
FROM student_enrollment se
INNER JOIN attendance_calendar ac
ON se.calendar_id = ac.calendar_id
WHERE se.student_id = se2.student_id
AND se.syear =2016 --{SYEAR}
AND ac.syear =2016 --{SYEAR}
AND ac.school_date >= se.start_date
AND ac.school_date <= NOW()
AND (se.end_date IS NULL OR ac.school_date <= se.end_date)
AND se.custom_9 IS NULL
AND se2.start_date >= '2016-08-22'
GROUP BY se.student_id
HAVING COUNT(ac.school_date) >= 59)
>= 59) AS se
LEFT JOIN custom_field_select_options cfso1
ON se.cfso1.id = cfso1.id
WHERE students.student_id = se.student_id
I found my problem whereby I had a syntax error in the ON condition "se.cfso1.id". Once I cleared that up the problem was resolved.

multiplication in group by , dyslexia

Now this is a simple insert query with one subquery and it's working perfectly:
INSERT INTO CSolutions..Report2
SELECT Nov.Chain, CG.Grouping, reg.code as regcode,reg.pname,reg.fname,reg.sname, SUM(NS.Currency) as sumeur , sum(ns2.kpl) as sumkpl,0,0,0,0
FROM CSolutions..NovSales NS,CSolutions..NSaleskpl NS2, CSolutions..NovCGroup CG, sales..reg_eng reg,
(SELECT DISTINCT P.Code, Nov.Chain
FROM Register..Pcy P
INNER JOIN Register..TCustomer TC ON (P.Code = TC.PCode)
INNER JOIN CSolutions..Novies2 Nov ON (TC.Code = Nov.TCode)
) AS Nov
WHERE NS.SpCode = CG.SpCode and ns.spcode = ns2.spcode AND Ns.PCode = Nov.Code
and ns.spcode = reg.code
and ns.pcode = ns2.pcode
**and NS.SalesMonth = '201205'
and NS2.SalesMonth = '201205'**
GROUP BY Nov.Chain, CG.Grouping , reg.code,reg.pname,reg.fname,reg.sname
This is derivate of the same query, but it's not working correctly:
INSERT INTO CSolutions..Report2
SELECT Nov.Chain, CG.Grouping, reg.code as regcode,reg.pname,reg.fname,reg.sname, SUM(NS.Currency) as sumeur , sum(ns2.kpl) as sumkpl,0,0,0,0
FROM CSolutions..NovSales NS,CSolutions..NSaleskpl NS2, CSolutions..NovCGroup CG, sales..reg_eng reg,
(SELECT DISTINCT P.Code, Nov.Chain
FROM Register..Pcy P
INNER JOIN Register..TCustomer TC ON (P.Code = TC.PCode)
INNER JOIN CSolutions..Novies2 Nov ON (TC.Code = Nov.TCode)
) AS Nov
WHERE NS.SpCode = CG.SpCode and ns.spcode = ns2.spcode AND Ns.PCode = Nov.Code
and ns.spcode = reg.code
and ns.pcode = ns2.pcode
**and NS.SalesMonth between '201201' and '201205'
and NS2.SalesMonth between '201201' and '201205'**
GROUP BY Nov.Chain, CG.Grouping , reg.code,reg.pname,reg.fname,reg.sname
This will give 5 times the 5 month sum amount,
I am a dyslexic and i have hard time to spot the error, I hope someone can help me ?? :)
There is no join on the salesmonth in CSolutions..NovSales and CSolutions..NSaleskpl NS2. In the frist query this does not matter because you are only looking at one salesmonth. In the second query I presume there are multiple salesmonth's as you are selecting a range of value from each table. You are getting a cross join because of this of salesmonth's because of this.