表tab
col1 col1 col2
1 1 ab
2 1 bc
3 1 bd
4 2 hu
5 2 nj
6 2 ih
7 3 ha
8 3 xj
9 3 ih
10 3 hc可以用group by得到以下结果 或者其它方法
col1 col1 col2
1 1 ab
2 1 bc
4 2 hu
5 2 nj
7 3 ha
8 3 xj
col1 col1 col2
1 1 ab
2 1 bc
3 1 bd
4 2 hu
5 2 nj
6 2 ih
7 3 ha
8 3 xj
9 3 ih
10 3 hc可以用group by得到以下结果 或者其它方法
col1 col1 col2
1 1 ab
2 1 bc
4 2 hu
5 2 nj
7 3 ha
8 3 xj
解决方案 »
- 求一份地区数据
- 菜鸟求:MySQL存储图片能够自行输入吗?还是用程序实现?
- mysql 查找指定节点下的所有子节点
- 今天做笔试遇到一个SQL的题目,没做出来,请教一下大家
- 问下日期算数中type的问题
- mysql4.0 里面的多表连接子句查询提示语法错误问题怎么解决?
- 请问下面两个sql语句哪个效率高?为什么?
- mysql中的数据能不能导入sqlserver2000中
- linux下mysql用c语言读取出来的信息没有空格怎么办?
- mysql索引都已经用上了,为什么还是显示Using filesort???
- mysql启动后句柄数4W多,什么原因。。急!!
- Mysql function select into不能给变量赋值
select *
from tab a
where 2>(select count(*) from tab where col1=a.col1 and col0<t.col0)
1 1 ab
2 1 bc
3 1 bd
4 2 hu
5 2 nj
6 2 ih
7 3 ha
8 3 xj
9 3 ih
10 3 hc
select a.col1,a.col2,a.col3 from tt a left join tt b
on a.col1=b.col1 and a.col3>=b.col3 a.col1,a.col2,a.col3 group by having count(b.col3)<=2
on a.col1=b.col1 and a.col3>=b.col3 group by a.col1,a.col2,a.col3
having count(b.col3) <=2
SELECT * FROM tab t1
WHERE 3>(SELECT COUNT(*) FROM tab WHERE col1=t1.col1 AND col0<=t1.col0)
ORDER BY t1.col1,t1.col0;
N>(select count(*) .会快一些。