mysql-php processing Database Multi-table, can be both efficient and clear how to deal with the idea?

Source: Internet
Author: User
"The situation is as follows"
Recorded in table 1
Bicycle number tenant Merchant

1           a     2           a3           b4           c

[Here's the meaning of the different merchant.] Owned bicycles, merchants own bicycle tables]

Table 2
Bike number rent out time rent out amount

1           2         41           3         51           6         102           3         53           4         7

[This means that. Different merchant on their own bike rental time different set price, bicycle Price table]

Table 3
Bike number rent out time rent the person

1          2        用户11          3        用户22          4        用户33          2        用户44          1        用户5[这里指,用户,在今天使用的自行车和租的时间,租车记录]

"Then the problem comes."
I want to know now.

1, Business today car rental, with 1 cars, total number of car rental
Finally to get
Bike Number Rented 2 hours a few times? How many times do you rent out 3 hours? How many times do you rent out 4 hours?

I have 2 different ways. The first is to use the program to find out the rental records of all cars. And then in the program to use the statistics to rent out the time, and how many times.
Ask this type of data statistics. How PHP is generally achieved can take into account efficiency. can be very concise again!

Reply content:

"The situation is as follows"
Recorded in table 1
Bicycle number tenant Merchant

1           a     2           a3           b4           c

[Here's the meaning of the different merchant.] Owned bicycles, merchants own bicycle tables]

Table 2
Bike number rent out time rent out amount

1           2         41           3         51           6         102           3         53           4         7

[This means that. Different merchant on their own bike rental time different set price, bicycle Price table]

Table 3
Bike number rent out time rent the person

1          2        用户11          3        用户22          4        用户33          2        用户44          1        用户5[这里指,用户,在今天使用的自行车和租的时间,租车记录]

"Then the problem comes."
I want to know now.

1, Business today car rental, with 1 cars, total number of car rental
Finally to get
Bike Number Rented 2 hours a few times? How many times do you rent out 3 hours? How many times do you rent out 4 hours?

I have 2 different ways. The first is to use the program to find out the rental records of all cars. And then in the program to use the statistics to rent out the time, and how many times.
Ask this type of data statistics. How PHP is generally achieved can take into account efficiency. can be very concise again!

This directly can be solved with SQL statements, with left join can find out any of the data you want, if you use PHP processing, once all the data are taken out, and then processing is also possible, do not cycle to query the database.

  • 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.