找符合这样条件的记录不:
多个记录具有相同的pId,
其中至少1条的Status为1,而且至少一条的Status不为1。这个语句如何写
表结构 (id,pid,status)如何做这个sql
多个记录具有相同的pId,
其中至少1条的Status为1,而且至少一条的Status不为1。这个语句如何写
表结构 (id,pid,status)如何做这个sql
解决方案 »
- sql 多条合并 进来都有分
- --with-thread-safe-client 编译选项
- 看安装了 MYSQL 可是插入中文就失败 Data too long for column 'clipname' at row 1
- MySQL实现双向同步,但其中的一台机器需要经常的重起,关闭这该如何办呢?
- 救急,关于mysql不能正确启动的问题,请指教!
- 有谁知道哪里有下载cobol的编译器,能在window下用的
- 修改表名后数据丢失,然后数据库表添加单个数据跳出来一个说我更改多条数据的警告。(在线等)
- 在windows server 上安装了mysql,部署了asp.net网站。访问数据库失败
- wamp在线考试系统搭建
- 为什么存储过程不能这样写,我要怎么写
- 如何用语句在,mysql一个表中添加一个字段
- 请教一条复合查询语句
select * from tb_name a where exists (select count(*) from tb_name b where b.pid=a.pid and b.status=1)>=1 and
exists (select count(*) from tb_name b where b.pid=a.pid and b.status<>1)>=1 group by pid having count(*)>1
最后得到的是不重复的记录我需要的是重复的记录
搞错了,改成这样就可以:select a.* from tb_mul a where (select count(*) from tb_mul b where b.pid=a.pid and b.status=1)>=1 and
(select count(*) from tb_mul b where b.pid=a.pid and b.status<>1)>=1
如果你的id是非重复的,而又要显示所有的重复记录,则把上面的改下也是可以用的:
select distinct a.* from tb_mul a,tb_mul b,tb_mul cwhere b.status=1and c.status<>1and a.pid=b.pidand a.pid=c.pid
from 表结构 a
where exists (select 1 from 表结构 where status=1)
and exists (select 1 from 表结构 where status!=1)