zoukankan      html  css  js  c++  java
  • 年月日产品分组报表

    SELECT sum(a.buycount) buycount,(SELECT c.name from tb_product_type_info c -- 按年
    WHERE c.id=b.typeid) typename,year(a.createdate)as year from tb_order_detail a,tb_product_pk b
    where a.productname=b.oldproduct GROUP BY b.typeid,year(a.createdate);

    SELECT sum(a.buycount) buycount,(SELECT c.name from tb_product_type_info c -- 按月
    WHERE c.id=b.typeid) typename,year(a.createdate)as year,month(a.createdate)as month from tb_order_detail a,tb_product_pk b
    where a.productname=b.oldproduct GROUP BY b.typeid,year(a.createdate),month(a.createdate);

    SELECT sum(a.buycount) buycount,(SELECT c.name from tb_product_type_info c -- 按周
    WHERE c.id=b.typeid) typename,year(a.createdate)as year,week(createdate,1) as week from tb_order_detail a,tb_product_pk b
    where a.productname=b.oldproduct GROUP BY b.typeid,year(a.createdate),week(a.createdate,1);

    SELECT sum(a.buycount) buycount,(SELECT c.name from tb_product_type_info c -- 按季
    WHERE c.id=b.typeid) typename,year(a.createdate)as year,quarter(createdate) as quarter from tb_order_detail a,tb_product_pk b
    where a.productname=b.oldproduct GROUP BY b.typeid,year(a.createdate),quarter(a.createdate);

    //--------------------------------0706--------------------------------

    select
    id,
    orderno,
    memberno,
    username,
    custname,
    sex,
    mobile,
    address,
    membertype,
    membercate,
    channeltype,
    count(id) ordercount,
    sum(payshop) orderpricetotal,
    (sum(payshop)/ count(id))orderperprice,
    sum(buycount) buycounttotal,
    (avg(subday)/30) perfreque
    from
    (select
    id,
    orderno,
    memberno,
    username,
    recivename AS custname,
    sex,
    ctmobile AS mobile,
    sendaddress AS address,
    membertype,
    membercate,
    channeltype,
    payshop,
    (select buycount from tb_crm_order_detail where orderno=a.orderno) buycount,
    (to_days((select createdate from tb_crm_order_info where createdate>a.createdate and username=a.username order by createdate limit 0,1))-to_days(createdate)) subday
    from tb_crm_order_info as a)b group by username;

    //------------------------------------------------------------

    select
    username,
    (avg(subday)/30) perfreque from(
    select * from (select
    username,
    (to_days((select createdate from tb_crm_order_info where createdate>a.createdate and username=a.username order by createdate limit 0,1))-to_days(createdate)) subday
    from tb_crm_order_info as a) as b where b.subday is not null)c group by username; -- 平均天数

    select username, (avg(subday)/30) perfreque from( select * from (select username, (to_days((select createdate from tb_crm_order_info where createdate>a.createdate and username=a.username order by createdate limit 0,1))-to_days(createdate)) subday from tb_crm_order_info as a) as b where b.subday is not null)c group by username; -- 平均天数

    select id, orderno, memberno, username, custname, sex, mobile, address, membertype, membercate, channeltype, count(id) ordercount, sum(payshop) orderpricetotal, (sum(payshop)/ count(id))orderperprice, (avg(subday)/30) perfreque from (select * from (select id, orderno, memberno, username, recivename AS custname, sex, ctmobile AS mobile, sendaddress AS address, membertype, membercate, channeltype, payshop, (to_days((select createdate from tb_crm_order_info where createdate>a.createdate and username=a.username order by createdate limit 0,1))-to_days(createdate)) subday from tb_crm_order_info as a) as b )c  group by username;

  • 相关阅读:
    C++虚函数表理解
    【转】c++虚函数实现原理
    【转】运输层TCP协议详细介绍
    【转】计算机中浮点数的表示
    ARP跨网段广播
    【转】arm和x86的区别
    面向对象六大原则
    安卓 热修复的原理
    Zygote和System进程的启动过程
    Android内存泄漏
  • 原文地址:https://www.cnblogs.com/fx2008/p/3171312.html
Copyright © 2011-2022 走看看