I want to sort products by popularity and discount(high to low).
How can I achieve?
You can use native table for select popularity and discount:
report_viewed_product_index - products popularity
(SUM(index_id) GROUP BY product_id)
discount = final_price - price
Also you can use comprehensive solution, like https://mirasvit.com/magento-2-improved-sorting.html which allows sort products by more 10 different factors and apply sorting by few factors in same time (set importance for each factor)