zoukankan      html  css  js  c++  java
  • mysql赋值变量:=的使用

    /**查询近两周销量,按照日期分组**/
    select tpdate.dateStr,ifnull(tpdata.count,0) as count from

    (SELECT @rownum:=@rownum+1 as count,date_add(DATE_FORMAT(now(),'%Y-%m-%d'),INTERVAL -@rownum day) as dateStr from (select @rownum:=-1)r,记录大于13条的任意表

    where @rownum < 13) tpdate

    left join (select sum(xxxtable.amount) as amount,DATE_FORMAT(sub.create_time,'%Y-%m-%d') as dateStr from xxxxtable where

    xxid=#{xxid} and create_time > date_add(now(),interval -13 day) and status in(x,x,x,x,x)

    group by dateStr) tpdata on tpdata.dateStr=tpdate.dateStr order by dateStr

    /**在父子节点的一张表中查找某条记录的根节点**/
    /**根据输入的id查询根节点id**/

    select IFNULL(@head_id,输入的id) from
    (

    select @head_id:=if(xxxtable.id=@head_id and xxxtable.parent_id>0,xxxtable.parent_id,@head_id)

    from (select @head_id:=输入的id)r,xxxtable order by xxxtable.id desc

    )rr limit 1;

  • 相关阅读:
    计算机基础(7)
    计算机基础(6)
    计算机基础(5)
    计算机基础(4)
    计算机基础(3)
    计算机基础(2)
    计算机基础(1)
    数组、函数
    js基础知识
    随笔3
  • 原文地址:https://www.cnblogs.com/AlanWinFun/p/15634176.html
Copyright © 2011-2022 走看看