Company: StoneX_22july
Difficulty: medium
Problem Description As part of a smart home application, you need to write a SQL query to calculate the total electricity consumption and the total invoicing cost for each user based on their meter readings. The billing system applies one of three general tariffs. Each tariff corresponds to a specific total consumption range. A single tariff is applied to a user's entire total consumption based on the range into which their cumulative consumption falls. This is a flat-rate pricing model per range, not a tiered or stepped model. Schema You are provided with the following tables: Table: accounts +----------+--------------+ | Column | Type | +----------+--------------+ | id | INT | | username | VARCHAR(255) | +----------+--------------+ PRIMARY KEY (id) Table: tariffs +-------------------+--------------------------------+ | Column | Type | +-------------------+--------------------------------+ | name | ENUM('A','B','C') | | consumption_range | ENUM('0-200','201-499','500-') | | cost | DEC