mysql 表 table PK(id,type) 关联表 table1 (多列+table.id+table.type) 在 table1 中 执行查询 select * from table1 group by id,type having count(querySql)=2 请问这个 querySql 该怎么写
mysql 表 table PK(id,type) 关联表 table1 (多列+table.id+table.type) 在 table1 中 执行查询 select * from table1 group by id,type having count(querySql)=2 请问这个 querySql 该怎么写
|
1
我目前用的是 having count(concat(id,type))=2 这样的方式 有没有更好的方式
|
|
akiraFeb 14, 2018
2
select id, `type`, ... , count(1) `c` from table1
where ... group by id, `type` having `c` =2 |
|
usednameFeb 14, 2018 via iPhone
3
ID type 做复合主键也是清奇
|
|
4
@akira 嗯 这个也不错 我之前在 子查询中 用到了 新增列 在标识 数据来自哪个表 我倒是忘了 可以复用这种方式
|
|
5
@usedname 多系统的应用 没有办法中的办法
|
|
6
@akira 不行 count ( 1 ) c 后 c 的列值都是 1 两个表 union all 后 再用 count()聚合函数 只有两条数据
|