테이블 구조 : tbl_transaction 및 tblCustomer 사이
tblCustomer다중 쿼리 서브 쿼리 가입
Customer_id created field1 field2 cardno field14
------------------------------------------------------------------------------------------------
1014 2010-05-25 12:51:59.547 Cell Phone [email protected] 1234567890 Test Card
1015 2010-08-15 12:51:59.547 Email [email protected] 2345678891 NULL
tbl_TransactionDishout
Trnx_id offerNo TerminalID Created VirtualCard
-------------------------------------------------------------------
1 1014 170924690436418 2010-05-25 12:51:59.547 1234567890
관계는 동일 cardno 데있다. ..
Enrolled Enrolled as Email Enrolled as Text Deals Redeemed
<First Date> 7 5 2 6
<Next Date> 9 3 6 14
날짜 제로 기록이있는 경우에도 두 테이블에서해야
Enrolled - Total No of records that is summation of Enrolled as Email and Enrolled as Text.
Enrolled as Email - Where field1 = 'Email' from tblCustomer table
Enrolled as Text - Where field1 = 'cell phone' from tblCustomer table
Deals Redeemed - Where field14 <> 'Test Card' from tblCustomer table and
where DishoutResponsecode = '0000' from tbl_Transaction table
내 기존 쿼리 :
는 일이 많다는 기록 아래와 같은 결과를 얻을 그것은 가능 tblCustomer 테이블에
SELECT
convert(varchar, CAST(ISNULL(t1.created,t2.created) AS DATETIME), 111) created,
COUNT(CASE WHEN (t1.field1 = 'E-mail' or t1.field1 = 'Cell Phone') and (t1.field14 <> 'Test Card' or t1.field14 is null) THEN 1 END) Enrolled,
COUNT(CASE WHEN t1.field1 = 'E-mail' and (t1.field14 <> 'Test Card' and t1.field14 is null) THEN 1 END) Enrolled_as_Email,
COUNT(CASE WHEN t1.field1 = 'Cell Phone' and (t1.field14 <> 'Test Card' and t1.field14 is null) THEN 1 END) Enrolled_as_Cell,
COUNT(CASE WHEN t2.DishoutResponseCode = '0000' and (IsNull(t1.field14, '') <> 'Test Card') THEN 1 END) Deals_Redeemed
FROM tblCustomer AS t1
FULL OUTER JOIN
tbl_TransactionDishout t2
ON t1.cardno = t2.VirtualCard and t1.created = t2.created
GROUP BY
convert(varchar, CAST(ISNULL(t1.created,t2.created) AS DATETIME), 111)
ORDER BY
convert(varchar, CAST(ISNULL(t1.created,t2.created) AS DATETIME), 111) DESC
마지막 4-5 기록
tbl_TransactionDisout 테이블에 515,created cardno field14
----------------------------------------------------------
2012-03-07 10:03:00.034 1234007600101240
2012-03-05 04:02:00.040 1234007600602122
2012-03-01 06:25:50.400 1234010400972168 Test Card
2012-03-01 30:05:30.022 555566669999 Test Card
2012-03-01 50:50:20.450 666677778888 Test Card
마지막 4-5 기록
created VirtualCard DishoutResponseCode
-----------------------------------------------------------------------
2012-03-09 13:18:02.703 1234010400972168 0010
2012-03-09 13:17:35.307 1234010400972168 0002
2012-03-09 13:17:14.237 1234010400972168 0007
2012-03-09 13:16:57.650 1234010400972168 0002
2012-03-08 21:13:57.137 1234010400475686 0000
2012-03-08 16:50:38.273 1234010400972168 0002
2012-03-08 16:50:26.070 1234010400972168 0007
2012-03-08 16:49:49.793 1234010400972168 0002
그래서 거기에 응답 코드 '0000'도 아닌 '테스트 카드'를 가진이 단지 하나 개의 카드입니다 ..하지만 코드 = '0000'을 가진 모든 카드를 가져오고 또한 '테스트 카드'를 가지고 있기 때문에 field14가 다른 테이블과 다른 날짜에 있기 때문에 비교할 수 없습니다.
이 같은 질문을 물어 아마 세 번째 날입니다. 매일 새로운 질문을하는 이유는 무엇입니까? – Jaques
@@Jaques 원하는 응답을 얻지 못하기 때문에 –
DishoutResponseCode를 지정했기 때문에 tbl_TransactionDishout 테이블의 레이아웃은 무엇입니까?하지만 상단에 표시하지 않습니다. 두 번째는과 이 시간을 제외한 날짜입니까? 하루에 그룹으로 묶으시겠습니까? –
Jaques