【发布时间】:2015-05-08 11:59:06
【问题描述】:
以下是我的数据库中的数据。
开始日期 - varchar
tablename - couponentry
coupon price month startingdate
100 15 1-month 02-03-2015
101 15 1-month 04-03-2015
102 15 1-month 05-03-2015
103 15 1-month 07-04-2015
104 15 1-month 08-04-2015
105 15 1-month 15-05-2015
106 15 1-month 18-05-2015
107 15 2-month 02-02-2015
108 15 2-month 04-02-2015
109 15 2-month 05-02-2015
110 15 2-month 07-03-2015
111 15 2-month 08-03-2015
112 15 2-month 15-05-2015
113 15 2-month 18-05-2015
114 15 2-month 18-05-2015
我需要基于 1 个月、2 个月等的总优惠券计数..还需要按月份显示单独的总优惠券总数。
FOR EX - 在上述数据中 - 1 个月内共创建了 7 张优惠券。 从这 3 张优惠券中,3 月来了,4 月 2 日,5 月 2 日.... 明智的...
预期输出如下
month jan feb mar april may june ... totalcoupon totalprice
1-month 3 2 2 7 105
2-month 3 2 3 8 120
以下是我尝试过的查询...
SELECT month,COUNT(CE.coupon) As Total,SUM(CE.Price) AS TotalPrice FROM coupon_entry CE LEFT JOIN subagentmaster SAM ON CE.subagentid = SAM.id LEFT JOIN tehsilmaster TM ON SAM.tehsil = TM.id LEFT JOIN city_master CM ON CE.city = CM.id WHERE CM.cityname = 'nagpur' GROUP BY CE.month
但这低于输出
month totalcoupon totalprice
1-month 7 105
2-month 8 120
【问题讨论】:
-
你试过 mid 或 substr 函数来提取月份吗?
-
你想在 (my)sql 中做这一切吗?
-
是的,它都在 mysql xampp 中
-
是的,我尝试了 mid 或 substr 函数来提取月份,但没有得到我想要的输出
-
我只需要按月打破总优惠券价值...在我的查询中...就是这样...对于前 1 个月内总共有 7 张优惠券...我还需要显示这 7..for ex - in March = 3,april - 2,may - 2 明智的月份计数......
标签: mysql