按列组合mysql查询 [英] combine mysql queries columnwise

查看:30
本文介绍了按列组合mysql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何要按列组合mysql查询吗?我有以下疑问

Is there anyway to combine mysql queries columnwise? I have below queries

select  count(ticket_id) as numInProgress from ost_ticket where status
 = 'in progress' and topic_id not in (select topic_id from ost_org_site_map)

 select  count(ticket_id) as numAssigned from ost_ticket where status =
 'open' and topic_id not in (select topic_id from ost_org_site_map)

我正在尝试以以下格式获得结果

and I am trying to get the result in the below format

---numInProgress | numAssigned---
            2    |     8
---------------------------------

推荐答案

只需将这些用作 select 语句中的子查询,例如

Just use these as subqueries in a select statement, e.g.

SELECT ($statement1$),($statement2$)

或您的查询:

SELECT (select count(ticket_id) as numInProgress from ost_ticket where status = 'in progress' and topic_id not in (select topic_id from ost_org_site_map)) as numInProgress ,(select count(ticket_id) as numAssigned from ost_ticket where status = 'open' and topic_id not in (select topic_id from ost_org_site_map)) as numAssigned;

这篇关于按列组合mysql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆