0
表結構:
tblCustomer tbl_transaction和tblCustomer由具有相同cardno之間只顯示非零行計數
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
關係。
現有查詢
SELECT
convert(varchar, CAST(t2.created AS DATETIME), 111) created,
COUNT(CASE WHEN t2.DishoutResponseCode = '0000' and t1.field14 <> 'Test card' THEN 1 END) as Deals_Redeemed,
COUNT(CASE WHEN t2.DishoutResponseCode <> '0000' and t1.field14 <> 'Test card' THEN 1 END) as Non_Deals
FROM tblCustomer AS t1, tbl_TransactionDishout t2
where t1.cardno = t2.VirtualCard
and convert(varchar, CAST(t2.created AS DATETIME), 111) >= (select MAX(convert(varchar, a.Created, 111))
from tbl_Offer as a,tbl_TransactionDishout as b where cast(a.OFID as varchar) = b.OfferNo and a.Live = '1')
GROUP BY convert(varchar, CAST(t2.created AS DATETIME), 111)
ORDER BY convert(varchar, CAST(t2.created AS DATETIME), 111) DESC
created Deals_Redeemed Non_Deals
-------------------------------------
2012/03/02 0 0
2012/03/01 0 1
2012/02/28 2 0
2012/02/27 0 0
現在我想用非零計數行..
相反的,你必須使用或...否則你是對的.. – 2012-03-15 11:32:33