SELECT 
  q_product_prices.product_id, 
  MIN(
    IF(
      q_product_prices.percentage_discount = 0, 
      q_product_prices.price, 
      q_product_prices.price - (
        q_product_prices.price * q_product_prices.percentage_discount
      )/ 100
    )
  ) AS price 
FROM 
  q_product_prices 
WHERE 
  q_product_prices.product_id IN (
    40744, 40745, 40758, 40759, 40761, 40768, 
    40769, 40770, 40776, 40788, 40789, 
    40790, 40791, 40792, 40793, 40794, 
    40795, 40796, 40809, 40821, 40827, 
    40828, 40829, 40830, 40831, 40832, 
    40833, 40834, 40835, 40836, 40837, 
    40839
  ) 
  AND q_product_prices.lower_limit = 1 
  AND q_product_prices.usergroup_id IN (0, 1) 
GROUP BY 
  q_product_prices.product_id

Query time 0.00104

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "78.21"
    },
    "grouping_operation": {
      "using_filesort": false,
      "table": {
        "table_name": "q_product_prices",
        "access_type": "range",
        "possible_keys": [
          "usergroup",
          "product_id",
          "lower_limit",
          "usergroup_id"
        ],
        "key": "product_id",
        "used_key_parts": [
          "product_id"
        ],
        "key_length": "3",
        "rows_examined_per_scan": 33,
        "rows_produced_per_join": 6,
        "filtered": "19.99",
        "index_condition": "(`portal`.`q_product_prices`.`product_id` in (40744,40745,40758,40759,40761,40768,40769,40770,40776,40788,40789,40790,40791,40792,40793,40794,40795,40796,40809,40821,40827,40828,40829,40830,40831,40832,40833,40834,40835,40836,40837,40839))",
        "cost_info": {
          "read_cost": "76.89",
          "eval_cost": "1.32",
          "prefix_cost": "78.21",
          "data_read_per_join": "158"
        },
        "used_columns": [
          "product_id",
          "price",
          "percentage_discount",
          "lower_limit",
          "usergroup_id"
        ],
        "attached_condition": "((`portal`.`q_product_prices`.`lower_limit` = 1) and (`portal`.`q_product_prices`.`usergroup_id` in (0,1)))"
      }
    }
  }
}

Result

product_id price
40744 65.000000
40745 129.000000
40758 49.000000
40759 49.000000
40761 45.000000
40768 19.000000
40769 19.000000
40770 29.000000
40776 333.000000
40788 49.000000
40789 29.000000
40790 55.000000
40791 34.000000
40792 39.000000
40793 49.000000
40794 49.000000
40795 119.000000
40796 69.000000
40809 6.000000
40821 59.000000
40827 49.000000
40828 49.000000
40829 59.000000
40830 49.000000
40831 59.000000
40832 59.000000
40833 79.000000
40834 55.000000
40835 119.000000
40836 55.000000
40837 39.000000
40839 26.000000