Preface
The data center charging system has been implemented for me many times. Now, as a mentor, we feel that the biggest benefit is ourselves. Every time they ask for something, they are actually urging themselves. In other words, you are always asking others for what they are and what they are.
It is difficult to know and operate easily, so some things need to be emphasized multiple times. The same is true for the charging system of the data center. The review and test have given me different understandings.
Problem Overview
This question is about composite queries. For composite queries, I have attached a picture. You can see what this composite query is like.
I will not talk about the business logic and robustness judgment here. The problem is: what will you find in the above query, the same as what you want to query?
Let me first explain the results I want to query: first perform the first two or operations, and then perform operations with the third. Therefore, this result should be empty.
However, it is only the result I want, but it is the result. Why?
Answer
The problem is that the priorities of and or keywords in the database are different. The and priority is higher than the or priority, so the result is inconsistent with the desire. This gives us a warning:ProgramWhen possible, use parentheses for priority calculation. Minimize error opportunities.
In-depth Problem
Now the question is, how can we add parentheses? First, let's talk about the running rules before the program is modified:
1. Define a string strsql = "select * From indicates where"
2. If you only query by one condition and assume that this condition is A, then strsql = strsql + a (A is the string of the first condition)
3. If two conditions exist and the string of the second condition is B, then strsql = strsql + B
4. If there are three conditions, the same as 3.
5. Execute the strsql statement.
Now we need to add parentheses between the first condition and the second condition. There are two kinds of Addition
First
Strsql + (
If one condition is used, a +)
Two conditions, strsql-), and then B +)
In this way, the first two conditions are always the first.
Second
Define another variable strendsql.
One condition, strendsql = strsql +,
Two conditions: strendsql = strsql + A + B
When there are three conditions, strendsql = strsql + (+ A + B +) + C
(Note: The two types mentioned above need to be combined with your ownCodeThink about it to make it clearer, noSource codeYou can leave a message, I will give you the source code)
In-depth Problem
In fact, the problem has been solved. Why don't you stop?
The reason is that I think this problem is representative. We are too lazy. The idea of Combined Query should be learned from the student information management system. This idea is deep-rooted, so every time we encounter such problems, we all think about it, so that we have encountered problems. The first idea is how to modify it.
I have to admit that new knowledge can be learned during the modification process. For example, after the first method is completed, you will be more familiar with string operations. But why do we have to stick to ourselves?
These are not the crystallization of my own thoughts, but the problems I encountered when I tested Haiyan. I was the first thought at the time. After he made the conversation, we didn't even think of the second one. It was just a method that I felt unfeasible, gave me this idea.
This kind of non-technical learning cannot be learned only by watching videos. Through communication with them, I feel that I have gained a lot.
Summary
It is good to follow the rules. But what's worse if we can break through the encirclement and experience the beauty of another world? Do not be banned from previous ideas. Similar problems may occur if you use the same solution. When a problem occurs, you can try another solution. Because similarity is not the same !!!