A.date1>A.date2 这个我觉得快不了,因为这个是会用全表扫描的。建议新增一个字段,比如flags,然后update一下这个字段,如果A.date1>A.date2 那么就是1,否则就是0.:update a
set = case when date1>date2 then 1 else 0 end这样,查询的时候,给这个flag字段建一个索引,速度就快了:select * from A where flag= 1
set = case when date1>date2 then 1 else 0 end这样,查询的时候,给这个flag字段建一个索引,速度就快了:select * from A where flag= 1
left join b
where a.kahaoid=b.kahaoid and a.xiaofeidate>b.shengjidate
(a表为消费表,b表为卡号表,a中为消费时间,b中为卡变成VIP时间)
就是要选取A表里面表示VIP消费的记录,SQL上面能改吗?