Best way to do subqueries?



1 comment

  • Avatar
    David Wynn


    The best way to do this in a single query is to use an if statement to turn the pass/fails into numbers. From there you can use a dummy variable coupled with the max operator to count up the failed and passed builds. An example query I ran on some fake data is below:

    | parse "* * *" as build,test,pass
    | if(pass="PASS",0,1) as pass_dummy
    // This line gives us the builds, each condensed into one record with a 1 for fails and 0 for passes
    | max(pass_dummy) by build
    | count as total_builds, sum(_max) as failed_builds
    | total_builds - failed_builds as passed_builds
    Comment actions Permalink

Please sign in to leave a comment.