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;

  • 相关阅读:
    欧几里得算法及扩展欧几里得(含)
    RP
    P1734_最大约数和
    The 2017 ACM-ICPC Asia East Continent League Final记录
    【数据结构】bzoj1651专用牛棚
    【数据结构】bzoj1455罗马游戏
    【数据结构】bzoj1636/bzoj1699排队
    【数据结构】bzoj3747Kinoman
    【计算几何】奇特的门
    Topcoder SRM 608 div1 题解
  • 原文地址:https://www.cnblogs.com/fx2008/p/3171312.html
Copyright © 2011-2022 走看看