• 年月日产品分组报表


    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;

  • 相关阅读:
    spring 好处与优点
    在SSH框架中使用Spring的好处
    xml配置文件详解
    了解OpenStack
    剖析云计算中的“共享型数据库”(转载)
    云计算开始。。。
    (一)使用springAPI以及自定义类 实现AOP-aop编程
    依赖注入之针对不同类型变量的几种注入方式
    Spring学习笔记--环境搭建和初步理解IOC
    hdu5305Friends dfs
  • 原文地址:https://www.cnblogs.com/fx2008/p/3171312.html
Copyright © 2020-2023  润新知