dongyi4170 2017-02-23 06:18
浏览 108

如何根据月份条件选择列

I have a mysql table like below,

Test : 

Id   start_Date    End Date      Points 
1     01-01-2017    15-01-2017     4 
2     01-02-2017    28-02-2017     5
3     16-01-2017    31-01-2017     5
4     01-03-2017    15-03-2017     3
5     16-03-2017    31-03-2017     4 
6     01-04-2017    30-04-2017     5

In this i want to select the Points based on Quatarwise ( Jan - Mar, Apr - Jun, Jul - Sep , Oct - Dec ).

I am trying the Following Query,

$q1 = "select sum(points) as point from Test where month(start_Date) Between '00' and '03' ";

    $q2 = "select sum(points) as point from Test where month(start_Date) Between '04' and '06' ";

    $q3 = "select sum(points) as point from Test where month(start_Date) Between '07' and '09' ";

    $q1 = "select sum(points) as point from Test where month(start_Date) Between '10' and '12' ";

i am getting the correct result . but what i want is ,

If any month having 2 rows of records then that particular month of records have to add and divide into 2 and sum into remaining 2 months.

Ex : Here jan month having 2 records ( 01 to 15 and 16 to 31 ) . so while getting the quarterwise result these 2 records want to add ( 4 + 5 = 9 ) and divide by 2 and take the points as jan month same for all months and finally want to get the quarterwise points.

How to do this in Mysql .

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题