Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example of a federated query in a database

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Xiaobian to share with you an example of federated query in the database, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The final result of the question is like this.

Isn't it easy?

However, the database looks like this

Ignore the renewal operation and only pay attention to the operation of borrowing and returning books.

That is to say, the same form and the same book can be either saved or returned, and the same book may be lent or returned many times.

Other attributes are easy to say, but what is more troublesome is the return time of the same book, which is followed by the return operation of borrowing books.

The solution goes like this:

Record the lending operation as table An and the return operation as table B: 22 rows in table An and 19 rows in table B.

The connection condition should be the number of the collection and the reader's id, and the result of the connection should be 58 lines. Because there are several numbers in the same book title in the data, I removed the book title, and the result of the connection is like this.

You can see that if the record box on the frame is the problem! What comes out of the frame is the same book borrowing record, which is connected to the return record of each item. As can be seen from the record, I asked this man to borrow the same book six times and made six connections!

The following rules can help us find the correct results.

1) the same group of loan and return operations, the borrowing operation must be before the return operation

2) after excluding the record of borrowing operation time > return operation time, the earliest return time is this person, the return time of this book.

The end result is this.

In the end, the SQL code looks like this

Select A. Operation time) return from aleft join bon a. The collection number of the book = b. The collection number of the book is and a. Reader id = b. Reader id and a. Operating time

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report