CREATE PROCEDURE proc_assign_tier_for_rewards(
@email varchar(255))
AS
BEGIN
SELECT tier_name, reward,min_amount,max_amount, CONCAT(min_amount, '-', max_amount) AS range
FROM reward_tier
WHERE (SELECT SUM(total_amount)
FROM dbo.orders
WHERE company_email = @email
) BETWEEN min_amount AND max_amount
END
GO
Use JOIN
as below to get desired output. Add o.total_amount in SELECT
statement to return total_amount
value.
CREATE PROCEDURE proc_assign_tier_for_rewards(
@email varchar(255))
AS
BEGIN
SELECT tier_name,
reward,
min_amount,
max_amount,
CONCAT(min_amount, '-', max_amount) AS range,
o.total_amount
FROM reward_tier rt
JOIN (SELECT SUM(total_amount) AS total_amount
FROM dbo.orders
WHERE company_email = @email
) o
ON o.total_amount BETWEEN rt.min_amount AND rt.max_amount
END
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.