【问题标题】:how to divide two queries如何划分两个查询
【发布时间】:2018-05-03 06:52:20
【问题描述】:

我想分为以下两个查询:

第一次查询:

select count_value from (select count(*) 
from jmeter 
where "project" = 'testmatrix' 
AND "suite" = 'apitest' 
AND "build"='132' 
AND "status" = 'ok' 
AND "page" != 'all' 
AND "metric" = 'count' 
AND "value"=0)

第二次查询:

select count_value 
from (select count(*) from jmeter 
where "project" = 'testmatrix' 
AND "suite" = 'apitest' 
AND "build"='132' 
AND "status" = 'ok' 
AND "page" != 'all' 
AND "metric" = 'count')

您的帮助将不胜感激,谢谢。

【问题讨论】:

  • 您想要一个 SQL 而不是两个?
  • 请提及输出
  • 第一个查询输出是 1,第二个查询输出是 2,那么总输出应该是 1/2 或 0.5

标签: sql influxdb


【解决方案1】:
SELECT SUM(CASE WHEN "Value"  = 0 THEN 1 ELSE 0 END)/COUNT(*) 
from jmeter 
where "project" = 'testmatrix' 
AND "suite" = 'apitest' 
AND "build"='132' 
AND "status" = 'ok' 
AND "page" != 'all' 
AND "metric" = 'count'

【讨论】:

  • 请始终为您的答案添加解释。
【解决方案2】:

这会有所帮助。

select sum(f_query)/ sum(S_query) as Result 
from (
    select  count(*) as f_query , 0 as S_query from jmeter where "project" = 'testmatrix' AND "suite" = 'apitest' AND "build"='132' AND "status" = 'ok' AND "page" != 'all' AND "metric" = 'count' AND "value"=0
    union all
    select 0 as f_query , count(*) as S_query  from jmeter where "project" = 'testmatrix' AND "suite" = 'apitest' AND "build"='132' AND "status" = 'ok' AND "page" != 'all' AND "metric" = 'count'
) as GroupTable

【讨论】:

  • 错误:解析查询时出错:在第 1 行找到联合,预期),字符 266,请您帮忙
  • 您使用的是哪个数据库服务器?
  • 我正在使用的influxdb数据库
  • select sum(f_query)/ sum(S_query) as Result from ( select count() as f_query , 0 as S_query from jmeter where project = 'testmatrix' AND suite = 'apitest' AND build='132' AND status = 'ok' AND page != 'all' AND metric = 'count' AND value=0 union all select 0 as f_query , count() as S_query from jmeter where project = ' testmatrix' AND suite = 'apitest' AND build='132' AND status = 'ok' AND page != 'all' AND metric = 'count' ) as GroupTable
  • 尝试高于希望,这样它就可以工作,否则尝试处理 santax 错误。我还没有安装 influxdb 这就是为什么不能检查 santax 错误。请理解查询逻辑。没关系。
猜你喜欢
  • 1970-01-01
  • 2022-12-06
  • 2020-01-24
  • 1970-01-01
  • 2021-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-22
相关资源
最近更新 更多