Skip to content

2205. The Number of Users That Are Eligible for Discount 👎

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
CREATE FUNCTION getUserIDs(startDate DATE, endDate DATE, minAmount INT) RETURNS INT
BEGIN
  RETURN (
    SELECT COUNT(DISTINCT user_id) AS user_cnt
    FROM Purchases
    WHERE
      time_stamp BETWEEN startDate AND endDate
      AND amount >= minAmount
  );
END