Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
2.2 kB
2
Indexable
Never
SELECT
	dcu.*,
	dcs.request_date,
	dcs.project_name,
	dcs.project_engineer,
	dcs.customer_name,
	dcs.bel_part_number,
	dcs.internal_record_number,
	dcs.customer_part_number,
	dcs.quote_identifier,
	dcs.estimated_annual_usage,
	dcs.production_timeframe,
	dcs.engineering_design_qualification,
	dcs.purchase_location,
	dcs.shipping_location,
	dcs.commission_rep_number,
	dcs.approved_by,
	dcs.approval_date,
	dcs.contract_manufacturer,
	dcs.quote_effective_date,
	dcs.record_creator_identifier,
	dcs.comments,
	dcs.distributor_who_is_purchasing,
	dcs.record_status,
	dcs.internal_part_number,
	dcs.origin_information,
	dcs.sales_code,
	dcs.manufacturing_location,
	dcs.split_design,
	dcs.territory,
	dcs.year,
	(
		CASE WHEN coalesce(dcs.distributor_who_is_purchasing, '') = '' THEN
			'No'
		ELSE
			'Yes'
		END) AS Disty,
	dcs.quarter,
	concat((
		SELECT
			group_concat(dcu2.commission_percentage ORDER BY dcu.id DESC separator '%, ')
			FROM belfserv_B.design_commissions_unique dcu2
		WHERE
			dcu2.design_commissions_shared_identifier = dcu.design_commissions_shared_identifier), '%') AS commission_rep_percentages, (
		SELECT
			group_concat(DISTINCT dcu2.rep_name ORDER BY dcu2.id DESC separator ', ')
		FROM
			belfserv_B.design_commissions_unique dcu2
		WHERE
			dcu2.design_commissions_shared_identifier = dcu.design_commissions_shared_identifier
		ORDER BY
			dcu.id DESC) AS rep_names
	FROM
		belfserv_B.design_commissions_unique AS dcu
		INNER JOIN belfserv_B.design_commissions_shared dcs ON dcs.id = dcu.design_commissions_shared_identifier
			AND((dcs. `bel_part_number` LIKE '%MeritageSale%')
			OR(dcs. `contract_manufacturer` LIKE '%MeritageSale%')
			OR(dcs. `customer_name` LIKE '%MeritageSale%')
			OR(dcs. `project_name` LIKE '%MeritageSale%')
			OR(dcs. `quote_identifier` LIKE '%MeritageSale%')
			OR(dcs. `record_status` LIKE '%MeritageSale%')
			OR(`rep_name` LIKE '%MeritageSale%')
			OR(dcs. `request_date` LIKE '%MeritageSale%')
			OR(dcs. `commission_percentage` LIKE '%MeritageSale%')
			OR(dcs. `customer_part_number` LIKE '%MeritageSale%')
			OR(dcu. `id` LIKE '%MeritageSale%')
			OR(dcs. `split_design` LIKE '%MeritageSale%'))
		ORDER BY
			dcu.id DESC
Leave a Comment