mysql:增删改查的一些基本操作

对Trades订单表的操作

查询当天所有充值记录
    SELECT * FROM trades WHERE DATE(create_time) = CURDATE();    

查询当天所有充值成功的订单(1为成功)
    SELECT * FROM trades WHERE DATE(create_time) = CURDATE() AND trade_type = 1;

统计当天充值成功的总金额
    SELECT SUM(trade_money) FROM trades WHERE DATE(create_time) = CURDATE() AND trade_type = 1;

查询昨天的全部订单
    SELECT * FROM trades WHERE DATEDIFF(create_time,NOW())=-1;

 查询昨天充值成功的订单    
    SELECT * FROM trades WHERE DATEDIFF(create_time,NOW())=-1 AND trade_type = 1;

统计昨天充值成功的总金额
    SELECT SUM(trade_money) FROM trades WHERE DATEDIFF(create_time,NOW())=-1 AND trade_type = 1;

查询昨天的全部订单(包括昨天和今天的数据)

    SELECT * FROM trades WHERE TO_DAYS(NOW()) - TO_DAYS( create_time) <= 1

你可能感兴趣的:(mysql:增删改查的一些基本操作)