The telephone numbers in the database are classified by long distance, local call, and international long distance.

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.