SQL expression to calculate the percentage

Maybe this answer I posted in another thread on using TSVB with the Metric Output and the Filter Ratio metric may be helpful to you