Mysql data retrieval problem.

Source: Internet
Author: User
I now have a table with no primary key. there is only one union unique (date, user_id, count_name,) Table record example: date: 20160808user_id: 556count_name: a1date indicates the date, user_id indicates the user id, and count_name indicates a statistical value. C...
  1. I have a table with no primary key and only one union is unique (date, user_id, count_name ,)
    Table record example: date: 20160808 user_id: 556 count_name: a1

  2. Date indicates the date, user_id indicates the user id, and count_name indicates a statistical value.

  3. Count_name can be set to a1, a2, a3,..., a12, b1, b2, b3,..., b12 );

  4. Tens of thousands of records are generated every day.

  5. The maximum number of records retrieved by the database is 10 thousand.

Now I need to count 12 values. The mysql statement can be used as follows:

select count(distinct(`shop_id`)) from count_table where date = '20160808' and count_name in ('a1','b1'); select count(distinct(`shop_id`)) from count_table where date = '20160808' and count_name in ('a2','b2'); ···

In this way, the database can be retrieved for 12 times, but the efficiency is not high.

Is there a way to retrieve the desired data at a time? (This is an old database with a large data volume. let's make the final consideration of modifying the database !)

Methods tried:

  1. In case of paging statistics, the table does not have a primary key, and the paging is not easy to process.

  2. One-time data extraction is being processed, because mysql can only retrieve about 10 thousand pieces of data at a time, and may crash even more.

Reply content:
  1. I have a table with no primary key and only one union is unique (date, user_id, count_name ,)
    Table record example: date: 20160808 user_id: 556 count_name: a1

  2. Date indicates the date, user_id indicates the user id, and count_name indicates a statistical value.

  3. Count_name can be set to a1, a2, a3,..., a12, b1, b2, b3,..., b12 );

  4. Tens of thousands of records are generated every day.

  5. The maximum number of records retrieved by the database is 10 thousand.

Now I need to count 12 values. The mysql statement can be used as follows:

select count(distinct(`shop_id`)) from count_table where date = '20160808' and count_name in ('a1','b1'); select count(distinct(`shop_id`)) from count_table where date = '20160808' and count_name in ('a2','b2'); ···

In this way, the database can be retrieved for 12 times, but the efficiency is not high.

Is there a way to retrieve the desired data at a time? (This is an old database with a large data volume. let's make the final consideration of modifying the database !)

Methods tried:

  1. In case of paging statistics, the table does not have a primary key, and the paging is not easy to process.

  2. One-time data extraction is being processed, because mysql can only retrieve about 10 thousand pieces of data at a time, and may crash even more.

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.