以下sql语句执行什么操作 [英] what does the following sql statement execute

查看:64
本文介绍了以下sql语句执行什么操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT DISTINCT 
	C.customer_key,
	SR.source_id,
	SR.wholesaler_code,
	SR.wholesaler_branch_code,
	SR.customer_code,
	SR.customer_name,
	SR.address_1+', '+ SR.address_2+', '+ CASE WHEN SR.address_3 = '' OR SR.address_3 IS NULL THEN '' ELSE SR.address_3 END  +', '+postal_code AS [address],
	ISNULL(M.orgcode,1) AS orgcode,
	B.bricknumber AS brick_id,
	'N' as customer_comark,
	'N' AS customer_growth,
	'N' AS customer_pn
--SELECT DISTINCT SR.*,c.source_ind ,c.wholesaler_branch_code--,W.wholesaler_branch_code
FROM stagedw.dbo.wholesaler_customer_pharmed_kzn_src SR --(889 row(s) affected)
INNER JOIN idxdw.dbo.idx_aspen_inmarket_customer C
	ON  SR.source_id = C.source_ind --'PHARM'
	AND SR.wholesaler_code = C.wholesaler_code
	AND SR.wholesaler_branch_code = C.wholesaler_branch_code
	AND SR.customer_code = C.customer_code
LEFT OUTER JOIN edw.dbo.dim_aspen_inmarket_customer IC
	ON  SR.customer_code = IC.customer_code
	AND SR.wholesaler_code = IC.wholesaler_code
	AND SR.wholesaler_code = IC.wholesaler_code
	AND SR.source_id = IC.source_id 
LEFT OUTER JOIN JNBVDW02A.edw.dbo.dim_ims_gsk_wholesaler W
	ON 	
		--C.wholesaler_branch_code = 'KZN' -- GTNG needs to be added.. W.wholesaler_branch_code
	--AND
	 C.wholesaler_code = W.wholesaler_code
LEFT OUTER JOIN (SELECT  wholesalerid,accnumber,orgcode,updatetype,d.wholesalerlinkid
				 FROM JNBVDW02A.pharmacare.dbo.medpages_wholesaler_org_link t 
					LEFT JOIN stagedw.dbo.st_medpages_wholesaler_org_link d
						ON d.wholesalerlinkid = t.wholesalerlinkid
					WHERE d.wholesalerlinkid IS NULL AND updatetype <> 'D'
				) AS M
	ON W.wholesaler_distributor_code = M.wholesalerid
	AND c.customer_code = M.accnumber
LEFT OUTER JOIN (SELECT 
					DISTINCT orgcode,bricknumber 
				FROM JNBVDW02A.pharmacare.dbo.medpages_organisation
				) AS B
	ON M.orgcode = B.orgcode
WHERE IC.customer_code IS NULL

推荐答案

这不是一个合理的问题.根据您的数据运行它.那就是它执行的.将其分解以查看其较小部分的功能,其中的每个选择都可以单独运行一条语句.因此,运行它们.购买一本SQL书籍并阅读.我们无权访问您的数据,并且当您最好阅读诸如外部联接之类的概念(它仅包含外部表中的所有记录,甚至包括那些记录)时,也不会花一个小时来对此进行解密.不匹配内部数据的),并处理数据,以了解其如何发挥作用.

总的来说,这看起来像是SQL的一个过于复杂的部分,肯定写得不好.无论哪种方式,无论谁提供给您,都应该向您解释.在我看来,就像盲人带领盲人一样.您最好以合理的速度学习SQL,而不是因为您的工作希望您做自己不知道该怎么做的事情.
This is not a reasonable question. Run it against your data. That''s what it executes. Break it down to see what smaller parts of it do, every select in there is a statement you can run on it''s own. So, run them. Buy a SQL book and read it. We don''t have access to your data and are not going to spend an hour deciphering this when you''d do better to read up on concepts like outer joins ( which just contains all the records in the outer table, even the ones that don''t match the inner one ), and play with the data, to learn how it works for yourself.

Overall, this looks like an over complex bit of SQL, it''s definitely poorly written. Either way, whoever gave it to you, should explain it to you, if they can. It looks like the blind leading the blind, to me. You''d do better to just learn SQL at a reasonable pace, not because your job expects you to do things you have no idea how to do.


这篇关于以下sql语句执行什么操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆