MySQL group statistics after the Order of the results (Union implementation)

Source: Internet
Author: User

Work with statistics December call records, statistics number dialed number, but the problem in a number can be dialed multiple times, each may or may not be connected, if the call Number Caller field group by group COUNT (*) after the number of statistics, This will cause can not see the statistics number of several are connected, a few are not connected, and then think of the Union is connected to the respective statistics, and then the statistical results in accordance with the number sorting together, the specific implementation of the following

billID (call log ID), caller (calling number), Callerstarttime (call time), Callerresult (dial result 0 not connected 1 on)

The SQL implementation statements are as follows:

  

 as date, Callresult,count as num from ' Sup_tel_record ' where Callerstarttime > 1417363200 and Callerstarttime < 1420041600 and Callresult = 0 GROUP by Caller unionselect bill_idasdate, C Allresult,countasdate ASC

The output results are as follows:

Note When using Union for SQL statement Connections, the first SQL statement cannot be ordered by using order BY, or it will appear

MySQL Error 1221 incorrect usage of union and ORDER by

MySQL group statistics after the Order of the results (Union implementation)

Related Article

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.