Home > database >  Does a great god, what is the difference between the two SQL statements, with and without parenthese
Does a great god, what is the difference between the two SQL statements, with and without parenthese

Time:09-24

The select WORKINFO. *
The from WORKINFO
WHERE to_char (createdate, 'yyyy')='2015'
AND WORKINFO. IsValid=1
AND (completeDate is not null AND to_char (completeDate, 'YYYY')='2015')
And (APPROVALDEPT in (select s.o id
The from sysorgan s
Where's arentorganoid=1
The or s.o id=1) or
Dutydeptoid in (select s.o id
The from sysorgan s
Where's arentorganoid=1
The or s.o id=1))
And workStatus & gt;=1
And isvalid=1
AND (extend4=2 or extend4 is null)
The ORDER BY DutyDeptOID ASC, WorkInfoNum DESC




The select WORKINFO. *
The from WORKINFO
WHERE to_char (createdate, 'yyyy')='2015'
AND WORKINFO. IsValid=1
AND (completeDate is not null AND to_char (completeDate, 'YYYY')='2015')
And (APPROVALDEPT in (select s.o id
The from sysorgan s
Where's arentorganoid=1
The or s.o id=1) or
Dutydeptoid in (select s.o id
The from sysorgan s
Where's arentorganoid=1
The or s.o id=1))
And workStatus & gt;=1
And isvalid=1
AND extend4=2 or extend4 is null
The ORDER BY DutyDeptOID ASC, WorkInfoNum DESC

CodePudding user response:

Carefully look at the AND AND OR logical operators of rules,

CodePudding user response:

Or inside the parentheses, the result set is filter other conditions after add filter conditions extend4=2 and extend4 is empty;
Or outside the parentheses, the result set is filter other conditions and extend4=2 to filter results, then the filtering results extend4 was empty and together,

For example:
Schools have three classes, the first filter is the class 1, the second filter conditions are boys or birthday in January,
As you write the difference is:
1, access to all the boys in the class 1, and 1 month birthday girl;
2, get all three class 1 month birthday boy student and the class 1,
The result of a lot more than 1 class 2 and class 3 students in January's birthday, understand?

CodePudding user response:

Thank you very much, you said very clearly,

CodePudding user response:

The or and the and the priority of the problem,

CodePudding user response:

Is not the same as the priority not> And> Or like the (2 + 3) with 10 * 10 * 2 + 3

CodePudding user response:

Just like addition and subtraction of priority in our math, add a bracket, identity class will go up, do what give priority to, NOT> AND> OR
  • Related