现在有流程记录表 t(序号 任务号 步骤审核角色 流程顺序号 审核状态)id tid role orderid status
1 3 CR 1 1
2 3 FS 2 0
3 3 CEO 3 0
4 2 CR 1 1
5 2 FS 2 1
6 2 CEO 3 0
7 4 CR 1 1
8 4 FS 2 0
9 4 CEO 3 0现在需要查出某用户角色 当前的审核数据我是这样写的,虽然是可以,但是效率比较低,最后面那句效率比较低,有没其他高效率的办法
select * from table t
where t.typeid=2
and t.role like concat('%','CEO','%')
and t.status=0
and t.id = (
select t1.id from table t1
where t.tid=t1.tid
and t1.status=0
order by t1.orderid asc limit 1)
1 3 CR 1 1
2 3 FS 2 0
3 3 CEO 3 0
4 2 CR 1 1
5 2 FS 2 1
6 2 CEO 3 0
7 4 CR 1 1
8 4 FS 2 0
9 4 CEO 3 0现在需要查出某用户角色 当前的审核数据我是这样写的,虽然是可以,但是效率比较低,最后面那句效率比较低,有没其他高效率的办法
select * from table t
where t.typeid=2
and t.role like concat('%','CEO','%')
and t.status=0
and t.id = (
select t1.id from table t1
where t.tid=t1.tid
and t1.status=0
order by t1.orderid asc limit 1)
解决方案 »
- 【求助】数据库数据取出出现乱码
- MYSQL中,有没有像在MSSQL的master.dbo.sysdatabases 保存着所有的数据库名称, xxxxxxx.dbo.sysobjects这样保存着所有的表名字段名等信息的系统表
- Mysql查询问题。。。
- mysql命令提示符出现了一个奇怪的问题,求助
- mysql error--救救我
- 一个数型数据库表如何得到相应的list!!!!
- 我通过JDBC连接MYSQL输入中文出现问题,请指教!
- 小弟从MSSQL来,学习MySQL,给份简明的操作说明可以不?
- 这个Sql语句怎么写?
- Mysql中如果count()函数出来的是0则没有返回记录,有没有什么方法可以使得它变得有返回
- Mysql 1524错误Plugin未加载
- 数据库多表查询,求帮忙拼一个sql语句
mysql> select tid,role from t where status=0 and tid=3 group by tid having max(orderid);
+------+------+
| tid | role |
+------+------+
| 3 | FS |
+------+------+
1 row in set (0.00 sec)mysql> select tid,role from t where status=0 and tid=2 group by tid having max(orderid);
+------+------+
| tid | role |
+------+------+
| 2 | CEO |
+------+------+
1 row in set (0.00 sec)mysql> select tid,role from t where status=0 and tid=4 group by tid having max(orderid);
+------+------+
| tid | role |
+------+------+
| 4 | FS |
+------+------+
1 row in set (0.00 sec)