美文网首页
连接临时表

连接临时表

作者: 苍老师的眼泪 | 来源:发表于2021-01-04 02:16 被阅读0次
    SELECT DAY(temp.last14day), ifnull(sum(orders.price), 0) as 'total'
    FROM (      
                select curdate() - INTERVAL (last14.num14) DAY as last14day     from (  select  0   as  num14   
                union all select 1             union all select 2             union all select 3             union all select 4             union all select 5             
                union all select 6             union all select 7             union all select 8             union all select 9             union all select 10
                union all select 11            union all select 12            union all select 13            union all select 14            ) as last14
    ) as temp
    left join orders on date_format(orders.created_at, '%Y-%m-%d') = temp.last14day group by temp.last14day order by temp.last14day desc limit 15;
    

    相关文章

      网友评论

          本文标题:连接临时表

          本文链接:https://www.haomeiwen.com/subject/zjrmoktx.html