custom sql statement

Record a part first, and then slowly add it later, so that you can check it later, and it is also convenient for everyone to learn together

/*Query the sum, and if there is a null value, assign a value of 0, while retaining two decimal places, group by time, and display the whole year*/

SELECT Convert((IFNUll(sum(value),'0')),DECIMAL(10,2)) 'value',create_date 'createDate' FROM `data`
 ${ew.customSqlSegment} (remark, this is the acceptance condition, I believe it should be understandable)
GROUP BY DATE_FORMAT(create_date,'%Y-%m')
ORDER BY create_date ASC

/*Query the sum, and assign a value of 0 if there is a null value, while retaining two decimal places, group by time, and display this month*/

SELECT Convert((IFNUll(sum(value),'0')),DECIMAL(10,2)) 'value',create_date 'createDate' FROM `data`
 ${ew.customSqlSegment}
GROUP BY DATE_FORMAT(create_date,'%Y-%m-%d')
ORDER BY create_date ASC

 /*Query the average value, and if there is a null value, assign a value of 0, while retaining two decimal places, group by time, and display this month*/

select Convert((IFNULL(AVG(TP),'0')),DECIMAL(10,2)) 'value',create_date,loction_type from prot_data
${ew.customSqlSegment}
group BY DATE_FORMAT(create_date,'%Y-%m-%d')
ORDER BY create_date ASC

/* queryWrapper in mybatis and mybatisplus has a select method that can splice SQL statements when building conditions*/

dataQueryWrapper.select(
        "IFNULL(SUM(water),0) water,IFNULL(SUM(gas),0) gas" +
                ",IFNULL(SUM(electricity),0) electricity" +
                ",IFNULL(SUM(feed),0) feed  "
);

Guess you like

Origin blog.csdn.net/xtldcn/article/details/129377198