For the data classification statistics in the database, determine the telephone number (the first digit is not 0 and the first digit is 0, but the second digit is not 0 and is classified as domestic long distance, the first and second values are both 0 and are classified as international long distances. Then, the amount of the class is summarized based on the time (settled once every day.
---------------------------------------------------------------
Select [date] = convert (varchar (10), date, 120 ),
[International long distance] = sum (case when substring (number, 1, 2) = '00'
Then isnull (amount, 0) else 0 end
),
[Domestic long distance] = sum (case when substring (number, 1, 2) <> '00' and substring (number, 1, 1) = '0' then isnull (amount, 0) else 0 end
),
[City Dialect] = sum (case when substring (number, 1, 1) <> '0' then isnull (amount, 0) else 0 end)
From table_name
Group by convert (varchar (10), date, 120)
---------------------------------------------------------------
Select time, sum (decode (substr (phone number,),... amount...) // or sqlserver case (when)
Group by time intercepted to day
---------------------------------------------
Select (case when left (number, 2) = '00' then 'International longhaul'
When left (number, 2) <> '00' and left (number, 1) = '0' then 'domestic long haul'
When left (number, 1) <> '0' then' dialect 'end) as [Classification],
Sum (amount)
From yourtable
Group by (case when left (number, 2) = '00' then' international long haul'
When left (number, 2) <> '00' and left (number, 1) = '0' then 'domestic long haul'
When left (number, 1) <> '0' then' 'end)