mysql 的一点点记录
以后再来整理。
-- 查询一个学校的报修单数
SELECT
s.id AS schoolId , -- 学校ID
COUNT(i.id) as cntId, -- 报修单数
IFNULL(t1.nohandlecnt,0) AS nohandlecnt,
IFNULL(t2.overcnt,0) AS overcnt,
ROUND(overcnt * 100 /COUNT(i.id),1) AS okRate
FROM
`t_issue` i
LEFT JOIN (
-- 完成报修单数
SELECT
s.id AS schoolId , -- 学校ID
IFNULL(COUNT(i.id),0) as overcnt -- 完成的报修单数
FROM
`t_issue` i
INNER JOIN t_school s ON i.school_id = s.id
WHERE i.completed_on IS NOT NULL and
i.acknowledged_on IS NOT NULL
GROUP BY
i.school_id
) t2 ON t2.schoolId = i.school_id
LEFT JOIN (
-- 未处理数
SELECT
s.id AS schoolId , -- 学校ID
IFNULL(COUNT(i.id),0) as nohandlecnt -- 未处理报修单数 FROM
`t_issue` i
INNER JOIN t_school s ON i.school_id = s.id
WHERE
i.acknowledged_on IS NULL AND
i.completed_on IS NULL GROUP BY
i.school_id
) t1 ON t1.schoolId = i.school_id
INNER JOIN t_school s ON i.school_id = s.id
GROUP BY
i.school_id
另一种保留小数的方法。
SELECT
TRUNCATE (avg(attitude), ) AS attitude,
TRUNCATE (avg(timeliness), ) AS timeliness,
TRUNCATE (avg(professionality), ) AS professionality,
TRUNCATE (avg(overall), ) AS overall
FROM (
SELECT
school_id,s.sc_name,
TRUNCATE (avg(attitude),) as attitude ,
TRUNCATE (avg(timeliness), ) as timeliness,
TRUNCATE (avg(professionality), ) as professionality,
TRUNCATE (avg(overall), ) as overall
FROM (
SELECT
t_repairmen.school_id ,
TRUNCATE (avg(attitude),) AS attitude,
TRUNCATE (avg(timeliness),) AS timeliness,
TRUNCATE (avg(professionality),) AS professionality ,
TRUNCATE (
(
avg(attitude) + avg(timeliness) + avg(professionality)
) / , ) AS overall
FROM `t_issue_rating`
INNER JOIN t_repairmen ON t_repairmen.id = t_issue_rating.repairmen_id
WHERE `is_dummy` = '' GROUP BY
repairmen_id,t_repairmen.school_id ) t
INNER JOIN t_school s ON t.school_id = s.id
WHERE
=
<if test="conditions.schools!=null">
AND school_id in (${conditions.schools})
</if>
GROUP BY school_id
ORDER BY
s.id DESC
) y
当遇到count 和group by 在一起,统计出的结果不正确时。
SELECT COUNT(DISTINCT id) FROM `xx` WHERE = group by id
两个表的count值相加
select
(select count(*) from bumen)+(select count(*) from mrs) as sum_count
查询用户所在的排名
SELECT
concat(
(
@dddd_row_num :=@dddd_row_num +
) +, ''
) AS row_id
FROM
history,
(SELECT @dddd_row_num := ) AS foo
WHERE
=
order by mp_send_time DESC
limit offset
各种统计count:
可以在统计count 的时候,将不符合条件的数排除在外
count(if( e.ext5 is NOT NULL ,true,null)) erijCount,
SELECT
c.classes_id AS examId,
i.eng_item_name AS examSubject,
c.classes_name AS examName,
eng_apply_start AS registStart,
eng_apply_end AS registEnd,
classes_status AS examStatus,
classes_fee AS examFee,
(
CASE
WHEN i.ext2 IS NOT NULL THEN
i.ext2
ELSE END
) AS examFee1,
A.realityApplyCount * classes_fee AS shouldApplyFee,
A.realityApplyFee,
A.realityApplyCount
FROM
eng_classes c
INNER JOIN eng_item i ON i.eng_id = c.eng_id
LEFT JOIN exam_examinee ON c.classes_id = examinee_exam_id
AND (
examinee_exam_status != ''
OR ISNULL(examinee_exam_status)
)
AND examinee_apply_type = 'english'
LEFT JOIN (
SELECT
classes_id AS Id,
count( IF (
examinee_pay_status = "",
TRUE,
NULL
)
) * classes_fee AS realityApplyFee,
count(DISTINCT examinee_id) realityApplyCount
FROM
eng_classes
INNER JOIN exam_examinee ON classes_id = examinee_exam_id
AND (
examinee_exam_status != ''
OR ISNULL(examinee_exam_status)
)
AND examinee_apply_type = 'english'
GROUP BY
classes_id
) AS A ON classes_id = A.Id
WHERE
=
GROUP BY
classes_id
还有这样一种,sum去叠加,中间加判断的。
SELECT
pro_apply_id AS examId ,
pro_apply_name AS examSubject,
pro_apply_start AS registStart ,
pro_apply_end AS registEnd ,
pro_apply_fee AS examFee ,
A.realityApplyCount * pro_apply_fee as shouldApplyFee,
A.realityApplyFee,
A.realityApplyCount
FROM pro_apply
LEFT JOIN exam_examinee ee ON pro_apply_id = ee.exam_item_id
AND examinee_apply_type = 'profession'
LEFT JOIN (
SELECT
apply_id AS Id ,
SUM(if(examinee_pay_status = "",item_fee,)) AS realityApplyFee ,
count(DISTINCT examinee_id) realityApplyCount
FROM
pro_item
INNER JOIN exam_examinee ee ON item_id = examinee_exam_id
AND (examinee_exam_status != '' OR ISNULL(examinee_exam_status))
AND examinee_apply_type = 'profession'
GROUP BY apply_id
) AS A ON A.Id LIKE CONCAT('%' ,pro_apply_id, '%')
mysql 的一点点记录的更多相关文章
- MYSQL删除表的记录后如何使ID从1开始
MYSQL删除表的记录后如何使ID从1开始 MYSQL删除表的记录后如何使ID从1开始 http://hi.baidu.com/289766516/blog/item/a3f85500556e2c09 ...
- mysql防止重复插入记录方法总结
mysql防止重复插入记录方法总结 防止mysql重复插入记录的方法有很多种,常用的是ignore,Replace,ON DUPLICATE KEY UPDATE,当然我们也可以在php中加以判断了. ...
- navicat MySQL 只有1000条记录
/*************************************************************************** * navicat MySQL 只有1000条 ...
- mysql 查询一条记录的下一条和上一条记录
如果ID是主键或者有索引,可以直接查找: 方法一: 查询上一条记录的SQL语句(如果有其他的查询条件记得加上other_conditions以免出现不必要的错误): select * from tab ...
- mysql中删除重复记录,只保留一条
表结构如下: mysql> desc test1; +--------------+------------------+------+-----+---------+------------- ...
- 【mysql】索引优化记录
基础知识 Innodb存储引擎 支持行锁 支持事务: Myisam存储引擎 只支持表锁: 不支持事务: 常见索引列表 独立的列 前缀索引(索引选择性) 多列索引(并不是多个单列索引,索引顺序很重要) ...
- mysql 删除表中记录
一.清除mysql表中数据 delete from 表名;truncate table 表名;不带where参数的delete语句可以删除mysql表中所有内容,使用truncate table也可以 ...
- MySQL Limit 限定查询记录数
MySQL Limit 限定查询记录数 MySQL LIMIT MySQL 中 LIMIT 关键字用于限定查询记录返回最大数目. 语法: ... LIMIT offset , rows 该语法中,of ...
- MySQL单表最大记录数不能超过多少?
MySQL单表最大记录数不能超过多少? 很多人困惑这个问题.其实,MySQL本身并没有对单表最大记录数进行限制,这个数值取决于你的操作系统对单个文件的限制本身. 从性能角度来讲,MySQL单表数据不要 ...
随机推荐
- 如何在 CentOS 7 中安装、配置和安全加固 FTP 服务
步骤 1:安装 FTP 服务器 1. 安装 vsftpd 服务器很直接,只要在终端运行下面的命令. # yum install vsftpd 2. 安装完成后,服务先是被禁用的,因此我们需要手动启动, ...
- EditPlus破解版|很不错的编辑器
Windows自带的notepad,功能一般.editplus,很值得推荐的编辑器! 注册秘钥: 用户名:www.dayanzai.me序列号:D2C86-E97A0-BF376-FDC33-27C1 ...
- struts2 中请求转发与请求重定向方法
本文转自:http://blog.csdn.net/a327736051/article/details/50240491 一.Chain Result:这个result调用另外的一个action,连 ...
- Android JUnit 入门指南
自动化单元测试可以做许多的事,并帮你节省时间.它也可以被用作快速检验新建工程或进行冒烟测试.始终,单元测试是作为一种有效的.系统的检验应用程序各功能执行的方式.Android SDK支持JUnit的自 ...
- Java程序作linux服务并且开机自动启动[转]
以有个java应用名称为test,打包为test.jar,程序入口为cn.com.ppnote.SocketServer. 下面在linux的/opt下建立testapp目录,复制test.jar到/ ...
- oc 调用c语言方法和oc的方法调用
//c语方的方法 void sayHello(){ printf("Hello OC"); } int main(int argc, char * argv[]) { sayHel ...
- 转Jmeter报告优化之New XSL stylesheet
Jmeter默认的报告展示的信息比较少,如果出错了,不是很方便定位问题.由Jmeter默认报告优化这篇文章可知,其实由.jtl格式转换为.html格式的报告过程中,style文件起了很关键的作用.下面 ...
- Linux内核中锁机制之完成量、互斥量
在上一篇博文中笔者分析了关于信号量.读写信号量的使用及源码实现,接下来本篇博文将讨论有关完成量和互斥量的使用和一些经典问题. 八.完成量 下面讨论完成量的内容,首先需明确完成量表示为一个执行单元需要等 ...
- Python min() 函数
描述 min() 方法返回给定参数的最小值,参数可以为序列. 语法 以下是 min() 方法的语法: min( x, y, z, .... ) 参数 x -- 数值表达式. y -- 数值表达式. z ...
- js中window.location.search的用法和作用。
用该属性获取页面 URL 地址: window.location 对象所包含的属性 属性 描述 hash 从井号 (#) 开始的 URL(锚) host 主机名和当前 URL 的端口号 hostnam ...