我有客户预订表,其中有多个客户也有一个客户可以有多个订单,所以从该表我必须找到客户的当前或活动订单。有两列从日期和到目前为止。我想要激活客户的跟踪订单并希望客户订单的回答计数有效。
答案 0 :(得分:1)
试试这个
position: relative
答案 1 :(得分:1)
使用Select Case和Between
Select
Order_id,Customer_id,
Case When CURDATE() BETWEEN FromDate And ToDate Then 'Active' Else 'Inactive' End as [Status]
From Order_table
<强>更新强>
Select
Count(*) as Total,Customer_id
From
Ordertable
Where
CURDATE() BETWEEN FromDate And ToDate And Customer_id = custid
Group By Customer_id
我使用Group By来避免重复显示相同的数据