当前位置: 代码迷 >> SQL >> 用普普通通sql代替rank函数
  详细解决方案

用普普通通sql代替rank函数

热度:94   发布时间:2016-05-05 09:59:29.0
用普通sql代替rank函数
select                  mt1.company as company,					       mt1.POLICY_HOLDER as policyHolderName,					       mt1.POLICY_HOLDER_id as policyHolderId,       					   mt1.recognizee as insuredName,		   				   mt1.recognizee_id as insuredCusId,                   mt1.age as age,								mt1.effective_date as validateDate,								mt2.name as productName,										mt1.maxpay as maxpay,       					   mt1.currency as productCurrency,       					   mt2.amount as amount,       					   mt1.totalpay as modePremium,       					   mt1.insure_status as policyStatus,                   mt1.tid as tid,                   mt1.create_id as agentNumber					from  gl_trade_policy mt1					     inner join 					      gl_tradel_product mt2					     on 					     mt1.tid = mt2.tradep_id and mt1.status = '1' and mt2.status = '1'					     inner join					      gl_cus_customer mt3					     on					     mt3.tid = mt1.recognizee_id					     inner join					      gl_cus_customer mt4					     on					     mt4.tid = mt1.POLICY_HOLDER_idwhere mt2.name = (select min(nt2.name) from gl_trade_policy nt1 inner join gl_tradel_product nt2 on nt1.tid = nt2.tradep_id group by nt1.tid having nt1.tid = mt1.tid)   union  select    null,    t2.policy_holder_name as policyHolderName,		t2.customer_id as policyHolderId,		t2.insured_name as insuredName,		t3.customer_id as insuredCusId,    t3.insured_age as age,    t2.validate_date as validateDate,    t4.product_name as productName,		t3.payment_period as maxpay,		t4.product_currency as productCurrency,    t3.amount as amount,    t2.MODE_PREMIUM as modePremium,    t2.policy_status as policyStatus,    t2.tid as tid,    t5.agent_number as agentNumber		from  gl_cus_accpect_manager t5		inner join		 gl_cus_accept_insurance t2		on t5.policy_code = t2.policy_code		inner join		 gl_cus_polagent t3		on		t2.policy_code = t3.policy_code		inner join		 gl_cus_accpect_product t4		on		t3.product_code = t4.product_codewhere t3.coverage_sql = (select min(bt2.coverage_sql) from gl_cus_accept_insurance bt1 inner join gl_cus_polagent bt2 on bt1.policy_code = bt2.policy_code group by bt1.policy_code having bt1.policy_code = t2.policy_code)
  相关解决方案