sql - 不同的计数并查看另一个表中的值
问题描述
我是一个针对不同数量的预订表的写作查询,其中使用、、、和字段进行like
搜索,还有一个客户应该属于美国的客户表。下面是我尝试过的代码,结果应该是单一的。'%gov%'
'%federal%'
'%army%'
billto
shipto
soldto
enduser
select (select distinct count (*)
from active_customer
where active_customer.Country = 'US'
),
(select count (distinct u.field)
from bookings
unpivot (field
for fields in (billto_name, shipto_name, soldto_name, end_user)
) u
where u.field like '%gov%' or u.field like '%federal%' or u.field like '%Army%'
)
结果:
4808 1105
结果不应组合在单独的行/列中。
解决方案
如果您的代码正在运行,但分别为您提供结果只需附加两列,如果您仍然有问题将它们转换为 varchar 然后附加它们,您将获得所需的结果。下面的例子
select (select distinct count (*)
from active_customer
where active_customer.Country = 'US'
)+' '+
(select count (distinct u.field)
from bookings
unpivot (field
for fields in (billto_name, shipto_name, soldto_name, end_user)
) u
where u.field like '%gov%' or u.field like '%federal%' or u.field like '%Army%'
)
推荐阅读
- angular - 如何每隔一段时间从 Firebase 实时数据库中获取数据。或获取数据并将其显示为实时数据
- cisco - 组取件场景 - CALL_STATE.CS_CONNECTED 未被触发
- regex - 我可以匹配任意长度字符串中另一个字符正下方的字符吗?
- php - 谷歌 API 分析 PHP 每天
- r - 从两个向量创建列表,每个向量的每个组合
- vuejs2 - 如何在 Vuetify v-data-table 中将选择复选框列移动到末尾?
- reactjs - 如何从 Redux 状态添加和删除属性
- c - 十六进制格式的 printf 浮点数返回随机值
- bash - 如何确定是否为 BASH 子外壳定义了 EXIT 陷阱?
- stl - STL 中的优先级队列实现