How can mysql-PHP process multiple databases and tables efficiently and clearly understand how to deal with them?

Source: Internet
Author: User
[Situation:] In table 1, the {code...} of the bicycle number tenant seller [indicates that different sellers. Bicycle owned by sellers] Table 2 Rental Amount of bicycle number rental time {code...} [meaning here. Different merchants have their own bicycles... [the situation is as follows]
In table 1
Bicycle number tenant merchant

1           a     2           a3           b4           c

[This means that different merchants. Bicycles owned by sellers]

Table 2
Bicycle No. Rental time Rental Amount

1           2         41           3         51           6         102           3         53           4         7

[This means. The price and price list set by different merchants for the rental time of their bicycles]

Table 3
The person who rented the bicycle number at the time of rental

1 2 users 11 3 users 22 4 users 33 2 users 44 1 user 5 [here, users, bicycles and rental time used today, car rental records]

[So the question is coming]
I want to know

1. Merchants rent a car today, with the same 1 car, total number of times of renting a car
Finally, you need to get
How many times does a bicycle number be rented out in 2 hours? How many times do I rent out three hours? How many times have I rented out for 4 hours?

I have 2 methods. The first is to use a program to first identify the rental records of all vehicles. Then, the program is used to calculate the rental time and the number of times.
This type of data statistics. In general, how can PHP achieve efficiency. And can be very concise!

Reply content:

[Situation]
In table 1
Bicycle number tenant merchant

1           a     2           a3           b4           c

[This means that different merchants. Bicycles owned by sellers]

Table 2
Bicycle No. Rental time Rental Amount

1           2         41           3         51           6         102           3         53           4         7

[This means. The price and price list set by different merchants for the rental time of their bicycles]

Table 3
The person who rented the bicycle number at the time of rental

1 2 users 11 3 users 22 4 users 33 2 users 44 1 user 5 [here, users, bicycles and rental time used today, car rental records]

[So the question is coming]
I want to know

1. Merchants rent a car today, with the same 1 car, total number of times of renting a car
Finally, you need to get
How many times does a bicycle number be rented out in 2 hours? How many times do I rent out three hours? How many times have I rented out for 4 hours?

I have 2 methods. The first is to use a program to first identify the rental records of all vehicles. Then, the program is used to calculate the rental time and the number of times.
This type of data statistics. In general, how can PHP achieve efficiency. And can be very concise!

This can be solved directly by using SQL statements. You can use the left join to find any data you want. If you use php to process it, retrieve all the data at a time, it is also possible to process the database again. Do not query the database again in a loop.

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.