将多个SQL组合到一个SQL中

时间:2017-09-26 05:44:21

标签: sql-server resultset multiple-resultsets

您有以下疑问

(SELECT COUNT(DISTINCT KUNDNR) CHECKED_CUSTOMER from CLNT0001.TCM_CHECK_SUMMARY
where '20170322000000000' <= HISTVON and HISTVON <  '20170323000000000' and INSTITUTSNR='0001') 

SELECT clientNumber
,creationDate
,customerNumber
,checkedCustomer
,CLNT0001.TCM_CHECK_SUMMARY.COUNTRY_CODE countryCode
,CLNT0001.TCM_CHECK_SUMMARY.PST_KURZTEXT personStatus
,CLNT0001.TCM_CASE_COUNTRY_GROUP.COUNTRY_CODE homeCountryCode
,CLNT0001.TCM_CASE_COUNTRY_GROUP.PST_LFD_NR personStatusId
,CLNT0001.TCM_CASE_COUNTRY_GROUP.REGULATION regulation
,caseStatus
,COC_SCORE_COUNT cocCaseCount
 FROM (
   SELECT GEPRUEFT_JN checkedCustomer
     ,INSTITUTSNR clientNumber
     ,KUNDNR customerNumber
     ,CASE_STATUS caseStatus
     ,MAX(CREATION_DATE) creationDate
   FROM CLNT0001.TAXACTCASE
   WHERE GEPRUEFT_JN = 'J' AND CREATION_DATE>='20170322000000000' AND 
CREATION_DATE<='20170323000000000'
   GROUP BY KUNDNR
     ,INSTITUTSNR
     ,GEPRUEFT_JN
     ,CASE_STATUS
 ) T1
 INNER JOIN CLNT0001.TCM_CHECK_SUMMARY ON T1.customerNumber = CLNT0001.TCM_CHECK_SUMMARY.KUNDNR
 INNER JOIN CLNT0001.TCM_CASE_COUNTRY_GROUP ON T1.customerNumber = CLNT0001.TCM_CASE_COUNTRY_GROUP.KUNDNR
 WHERE T1.creationDate <= CLNT0001.TCM_CHECK_SUMMARY.HISTBIS
  AND T1.creationDate >= CLNT0001.TCM_CHECK_SUMMARY.HISTVON

我需要CHECKED_CUSTOMER列作为第二个查询结果集的一部分,我无法找到一种方法来实现这一点,这可能吗?

1 个答案:

答案 0 :(得分:0)

<?php
if (isset($_POST['ok'])) {
    $precios = $_POST['precios'];
    $preciosarr = explode(",", $precios);
    print_r($preciosarr);
}
?>