PHP+MYSQL环境!
表是这样的
ID name sorid
1 xx 2
2 xx 2
3 xx 2
4 xx 3
5 xx 3
6 xx 3
7 xx 4
8 xx 4
9 xx 4相同sortid的只取2条,多余的不要,请问这样的sql语句应该怎么写!能实现吗?
表是这样的
ID name sorid
1 xx 2
2 xx 2
3 xx 2
4 xx 3
5 xx 3
6 xx 3
7 xx 4
8 xx 4
9 xx 4相同sortid的只取2条,多余的不要,请问这样的sql语句应该怎么写!能实现吗?
解决方案 »
- 类里如何定义中文字符属性?
- php连接MSSQL(有难度)
- 有没有 关于PHP 实例项目开发的书 就是教 各种项目原理的 那种书
- 关于在PHP页面上显示图片的问题
- 碰到一个棘手的SQL语句:根据输入的关键词来获取表中三个字段中是否有相同的记录
- Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2)
- 请问同时发邮件给多个人时的一个问题~~~
- 请问jpgraph画图类怎么调试。请看一下这个报错是怎么回事?
- mysql的root的密码怎么改呀?
- 关于php批量插入数据
- 求救:apache在加载PHP模块后不能启动!!!
- 程序的熟练问题
select * from tbl_name t1 where (select count(*) from tbl_name t2 where t2.sortid=t1.sortid and t2.id < t1.id) < 2
另外,为保证性能,sortid字段应设置为索引。
先
select dinstinct sortid from $table
查询出所有的sortid
得到数组$row
for($row as $ele){
$query="select * from $table where sortid='$ele' limit 0,2;";
}
这样会效率低一点,但是肯定可行!