现在有流程记录表 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)
解决方案 »
- 多线程访问这两句代码,是不是要加锁?
- 求存储过程写法
- 菜鸟求救,关于查询的问题
- 求一句SQL(去除表中只出现过一次行)
- 急!mysql中是否有select top n from 表的语句,如果没有,是否有其他方法可代替实现?
- mysql中insert语句插入汉字正常,改成存储过程就不行了,估计你没碰到过!
- 高分求救: linux下的mysql问题.(在线等)
- 有点奇怪,php+mysql从数据库存取资料时有时会乱码,是php的bug还是mysql的?不会只有我碰见吧?(ipman)
- 【在线等】这条查询语句如何优化
- 新人求助基础的MySQL问题
- 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)