php - mysql 如何对同一张表的相似的查询结果进行合并(就是条件不同而已)?
PHPz
PHPz 2017-04-10 17:44:17
0
3
236

譬如
select count(*) from A where type = 'dog'

select count(*) from A where type = 'cat'

这两个怎么合并呢?

这里我只是举个例子
每个类型的结果我都是需要的,另外条件查询会更复杂的,可能还是 addtime > And addtime < **

PHPz
PHPz

学习是最好的投资!

全部回复(3)
PHPzhong

直接用 UNION ALL 合并查询内容可否

SELECT count(*), 'dog' as type FROM A WHERE type='dog' 
UNION ALL
SELECT count(*), 'cat' as type FROM A WHERE type='cat' AND addtime > '2016-0-11-14'
伊谢尔伦

type IN ('dog','cat')

Peter_Zhu
select count(*) from A where (type = 'dog' or type = 'cat')
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板