{"id":962,"date":"2020-07-20T10:02:27","date_gmt":"2020-07-20T05:32:27","guid":{"rendered":"http:\/\/pahlevanzadeh.net\/?p=962"},"modified":"2020-07-20T10:11:30","modified_gmt":"2020-07-20T05:41:30","slug":"%d9%86%d9%88%d8%b4%d8%aa%d9%86-query-%d9%87%d8%a7%db%8c-sql-%d8%a8%d8%a7-django-%d9%82%d8%b3%d9%85%d8%aa-%d8%af%d9%88%d9%85%d9%86%da%af%d8%a7%d9%87%db%8c-%d8%a8%d9%87-%d8%b9%d9%85%d9%84%da%af%d8%b1","status":"publish","type":"post","link":"https:\/\/pahlevanzadeh.net\/?p=962","title":{"rendered":"\u0646\u0648\u0634\u062a\u0646 Query \u0647\u0627\u06cc SQL \u0628\u0627 Django (\u0642\u0633\u0645\u062a \u062f\u0648\u0645[\u0646\u06af\u0627\u0647\u06cc \u0628\u0647 \u0639\u0645\u0644\u06af\u0631\u200c\u0647\u0627\u06cc SQL])"},"content":{"rendered":"\n<p>\u062f\u0631 \u0627\u06cc\u0646 \u0642\u0633\u0645\u062a \u0633\u0639\u06cc \u0628\u0631 \u0622\u0646 \u062f\u0627\u0631\u06cc\u0645 \u062a\u0627 \u0639\u0645\u0644\u06af\u0631\u0647\u0627\u06cc \u0627\u0635\u0644\u06cc \u06a9\u0647 \u062f\u0631 <em>SELECT<\/em> \u0646\u0648\u0634\u062a\u0647 \u0645\u06cc\u200c\u0634\u0648\u062f \u0631\u0627 \u062f\u0631 Django \u0628\u0646\u0648\u06cc\u0633\u06cc\u0645. \u0633\u0639\u06cc \u0628\u0631 \u0622\u0646 \u0627\u0633\u062a \u062a\u0627 \u0628\u0627 \u0645\u062b\u0627\u0644\u200c\u0647\u0627\u06cc\u06cc \u0628\u062a\u0648\u0627\u0646 \u0633\u0631\u0639\u062a \u0628\u0627\u0644\u0627\u06cc \u06a9\u0627\u0631 \u0628\u0627 \u0627\u06cc\u0646 ORM \u0631\u0627 \u0628\u0631\u0631\u0633\u06cc \u06a9\u0631\u062f.<\/p>\n<p><a href=\"http:\/\/pahlevanzadeh.net\/wp-content\/uploads\/2020\/07\/python-django-1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignleft wp-image-935 size-medium\" src=\"http:\/\/pahlevanzadeh.net\/wp-content\/uploads\/2020\/07\/python-django-1-300x100.png\" alt=\"Python\/Django\" width=\"300\" height=\"100\" srcset=\"https:\/\/pahlevanzadeh.net\/wp-content\/uploads\/2020\/07\/python-django-1-300x100.png 300w, https:\/\/pahlevanzadeh.net\/wp-content\/uploads\/2020\/07\/python-django-1-1024x341.png 1024w, https:\/\/pahlevanzadeh.net\/wp-content\/uploads\/2020\/07\/python-django-1-768x256.png 768w, https:\/\/pahlevanzadeh.net\/wp-content\/uploads\/2020\/07\/python-django-1-1536x512.png 1536w, https:\/\/pahlevanzadeh.net\/wp-content\/uploads\/2020\/07\/python-django-1-2048x683.png 2048w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>\u0633\u0639\u06cc \u0634\u062f\u0647 \u062a\u0627 \u0644\u06cc\u0633\u062a\u06cc \u0627\u0632 \u0639\u0645\u0644\u06af\u0631\u0647\u0627\u06cc <em>WHERE<\/em> \u0628\u0631\u0631\u0633\u06cc \u0634\u0648\u0646\u062f.<\/p>\n<p>\u0628\u0631\u0627\u06cc \u06a9\u0627\u0631 \u0628\u0627 \u0639\u0645\u0644\u06af\u0631\u0647\u0627 \u062f\u0631 \u0627\u0628\u062a\u062f\u0627 \u0646\u06cc\u0627\u0632 \u0627\u0633\u062a \u0645\u062b\u0627\u0644\u200c\u0647\u0627\u06cc \u06a9\u0648\u0686\u06a9\u06cc \u0628\u0631\u0627\u06cc \u062e\u0648\u062f <em>SELECT<\/em> \u0632\u062f\u0647 \u0634\u0648\u062f.<!--more--><\/p>\n<p><strong>\u0645\u062b\u0627\u0644\u200c\u0647\u0627\u06cc \u0633\u0627\u062f\u0647:<\/strong><\/p>\n<p>\u0628\u0631\u0646\u0627\u0645\u0647\u200c\u0646\u0648\u06cc\u0633 \u0646\u06cc\u0627\u0632 \u062f\u0627\u0631\u062f \u062f\u0631 \u062d\u06cc\u0646 \u06a9\u0627\u0631 \u0628\u0627 ORM \u0628\u0631\u0627\u06cc \u062f\u06cc\u0628\u0627\u06af \u06cc\u06a9\u0628\u0627\u0631 query \u06cc \u06a9\u0647 run \u0645\u06cc\u200c\u0634\u0648\u062f \u0631\u0627 \u0628\u0628\u06cc\u0646\u062f \u062a\u0627 \u0628\u0627 \u062e\u0631\u0648\u062c\u06cc \u0645\u0642\u0627\u06cc\u0633\u0647 \u06a9\u0646\u062f. \u0628\u062f\u06cc\u0646 \u0645\u0646\u0638\u0648\u0631 \u0645\u062a\u063a\u06cc\u0631 <em>query<\/em> \u0628\u0647 \u0634\u06a9\u0644 \u0632\u06cc\u0631 \u062a\u0647\u06cc\u0647 \u0634\u062f\u0647 \u0627\u0633\u062a:<\/p>\n<pre class=\"theme:python font:liberation-mono font-size:14 nums:true line-height:20 toolbar:2 scroll:true lang:python decode:true plain:false\">q = EmployeePayTbl.objects.all()\nprint(q.query)<\/pre>\n<p>\u062e\u0631\u0648\u062c\u06cc:<\/p>\n<pre class=\"theme:dark-terminal font:liberation-mono font-size:14 nums:false line-height:20 toolbar:2 scroll:true lang:sh decode:true plain:false\">SELECT `EMPLOYEE_PAY_TBL`.`EMP_ID`, `EMPLOYEE_PAY_TBL`.`POSITION`, `EMPLOYEE_PAY_TBL`.`DATE_HIRE`, `EMPLOYEE_PAY_TBL`.`PAY_RATE`, `EMPLOYEE_PAY_TBL`.`DATE_LAST_RAISE`, `EMPLOYEE_PAY_TBL`.`SALARY`, `EMPLOYEE_PAY_TBL`.`BONUS` FROM `EMPLOYEE_PAY_TBL`<\/pre>\n<p>\u062f\u0631 \u0648\u0627\u0642\u0639 \u0628\u0627\u0644\u0627 <em>SELECT<\/em> \u0631\u0627 \u0628\u0627 * \u06cc\u0627 \u06a9\u0644 \u0641\u06cc\u0644\u062f\u200c\u0647\u0627 \u0635\u062f\u0627 \u0632\u062f\u06cc\u0645\u060c \u0627\u0645\u0627 \u0627\u06af\u0631 \u0628\u062e\u0648\u0627\u0647\u06cc\u0645 \u0641\u06cc\u0644\u062f\u200c\u0647\u0627\u06cc \u062e\u0627\u0635\u06cc \u0628\u0627\u0632\u06af\u0631\u062f\u0646\u062f \u0628\u0647 \u0635\u0648\u0631\u062a \u0632\u06cc\u0631 \u0639\u0645\u0644 \u0645\u06cc\u200c\u06a9\u0646\u06cc\u0645:<\/p>\n<pre class=\"theme:python font:liberation-mono font-size:14 nums:true line-height:20 toolbar:2 scroll:true lang:python decode:true plain:false\">q = EmployeePayTbl.objects.values_list('pay_rate')\nprint(q)<\/pre>\n<p>\u0648 \u0627\u06af\u0631 <em>query<\/em> \u0631\u0627 \u067e\u0631\u06cc\u0646\u062a \u0628\u06af\u06cc\u0631\u06cc\u0645 \u062f\u06cc\u06af\u0631 \u0633\u0627\u06cc\u0631 \u0641\u06cc\u0644\u062f\u200c\u0647\u0627 \u0648\u062c\u0648\u062f \u0646\u062f\u0627\u0631\u0646\u062f.<\/p>\n<p>\u0648 \u062e\u0631\u0648\u062c\u06cc \u062f\u0648 \u062e\u0637 \u06a9\u062f \u0628\u0627\u0644\u0627 \u0628\u062f\u06cc\u0646 \u0635\u0648\u0631\u062a \u0645\u06cc\u200c\u0634\u0648\u062f:<\/p>\n<pre class=\"theme:dark-terminal font:liberation-mono font-size:14 nums:false line-height:20 toolbar:2 scroll:true lang:sh decode:true plain:false\">&lt;QuerySet [(None,), (Decimal('11.00'),), (None,), (None,), (Decimal('14.75'),), (Decimal('15.00'),)]&gt;<\/pre>\n<p>\u062f\u0631 \u0648\u0627\u0642\u0639 query \u0628\u062f\u06cc\u0646 \u0635\u0648\u0631\u062a \u0634\u062f:<\/p>\n<pre class=\"theme:sql font:liberation-mono font-size:14 nums:false line-height:20 toolbar:2 scroll:true lang:sql decode:true plain:false\">SELECT `EMPLOYEE_PAY_TBL`.`PAY_RATE` FROM `EMPLOYEE_PAY_TBL`<\/pre>\n<p><strong>\u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 WHERE:<\/strong><\/p>\n<p>\u062a\u0627\u0628\u0639 <em>get<\/em> \u0641\u0642\u0637 \u06cc\u06a9 row \u0628\u0631\u0627\u06cc \u0634\u0645\u0627 \u0628\u0631\u0645\u06cc\u200c\u06af\u0631\u062f\u0627\u0646\u062f. \u0628\u0647 \u06a9\u062f \u0632\u06cc\u0631 \u062f\u0642\u062a \u06a9\u0646\u06cc\u062f:<\/p>\n<pre class=\"theme:python font:liberation-mono font-size:14 nums:true line-height:20 toolbar:2 scroll:true lang:python decode:true plain:false\">q = EmployeePayTbl.objects.get(position=\"SHIPPER\")\nq = print(q)\n<\/pre>\n<p>\u06a9\u062f \u0628\u0627\u0644\u0627 \u0628\u0647 \u062f\u0644\u06cc\u0644 \u0627\u06cc\u0646\u06a9\u0647 \u062f\u0627\u062f\u0647 SHIPPER \u0628\u06cc\u0634\u062a\u0631 \u0627\u0632 \u06cc\u06a9\u0628\u0627\u0631 \u062f\u0631 \u062c\u062f\u0648\u0644 \u0648\u062c\u0648\u062f \u062f\u0627\u0631\u062f \u062e\u0637\u0627\u06cc \u0632\u06cc\u0631 \u0631\u0627 \u0628\u0631 \u0645\u06cc\u200c\u06af\u0631\u062f\u0627\u0646\u062f:<\/p>\n<pre class=\"theme:dark-terminal font:liberation-mono font-size:14 nums:false line-height:20 toolbar:2 scroll:true lang:sh decode:true plain:false\">get() returned more than one EmployeePayTbl -- it returned 2!<\/pre>\n<p>\u06a9\u0627\u0631\u0628\u0631\u062f \u0627\u06cc\u0646 \u062a\u0627\u0628\u0639 \u0632\u0645\u0627\u0646\u06cc \u0627\u0633\u062a \u06a9\u0647 \u0634\u0645\u0627 \u0641\u0642\u0637 \u06cc\u06a9 row \u0645\u06cc\u200c\u062e\u0648\u0627\u0647\u06cc\u062f \u0628\u0631\u06af\u0631\u062f\u0627\u0646\u06cc\u062f. \u0645\u062b\u0627\u0644 \u062e\u0648\u0628 \u0627\u06cc\u0646 \u062a\u0627\u0628\u0639 \u062f\u0631 \u067e\u06cc Primary Key \u0647\u0627 \u0645\u06cc\u200c\u0628\u0627\u0634\u062f.<\/p>\n<p>\u0628\u0647 \u062c\u0627\u06cc \u062a\u0627\u0628\u0639 <em>get<\/em> \u0645\u06cc\u200c\u062a\u0648\u0627\u0646 \u0627\u0632 \u062a\u0627\u0628\u0639 <em>filter<\/em> \u0628\u0631\u0627\u06cc \u062d\u0644 \u0627\u06cc\u0646 \u0645\u0648\u0636\u0648\u0639 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0631\u062f \u06a9\u0647 \u0628\u0647 \u062a\u0641\u0635\u06cc\u0644 \u062c\u0644\u0648\u062a\u0631 \u062e\u0648\u0627\u0647\u06cc\u0645 \u067e\u0631\u062f\u0627\u062e\u062a.<\/p>\n<p>\u0628\u0647 query \u0632\u06cc\u0631 \u062f\u0642\u062a \u06a9\u0646\u06cc\u062f:<\/p>\n<pre class=\"theme:sql font:liberation-mono font-size:14 nums:false line-height:20 toolbar:2 scroll:true lang:sql decode:true plain:false\">select DATE_HIRE from EMPLOYEE_PAY_TBL where EMP_ID &gt;= 311549902;<\/pre>\n<p><strong>\u0646\u06a9\u062a\u0647:<\/strong> \u0641\u0631\u0636 \u0628\u0631 \u0627\u06cc\u0646 \u0627\u0633\u062a \u06a9\u0647 \u0634\u0645\u0627 \u0628\u0646\u0627 \u0628\u0631 \u0645\u0637\u0644\u0628 \u0642\u0628\u0644\u06cc \u062f\u0627\u062f\u0647\u200c\u0647\u0627 \u0631\u0627 import \u06a9\u0631\u062f\u0647\u200c\u0627\u06cc\u062f.<\/p>\n<p>\u062e\u0631\u0648\u062c\u06cc SQL \u0628\u0627\u0644\u0627 \u0686\u0646\u06cc\u0646 \u0645\u06cc\u200c\u0634\u0648\u062f:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"theme:dark-terminal font:liberation-mono font-size:14 nums:false line-height:20 toolbar:2 scroll:true lang:sh decode:true plain:false\">+------------+\n| DATE_HIRE  |\n+------------+\n| 1999-05-23 |\n| 2007-06-28 |\n| 2000-06-17 |\n| 2001-01-14 |\n+------------+\n<\/pre>\n<p>\u0628\u0647 \u062a\u06a9\u0647 \u06a9\u062f \u0632\u06cc\u0631 \u062f\u0642\u062a \u06a9\u0646\u06cc\u062f:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"theme:python font:liberation-mono font-size:14 nums:true line-height:20 toolbar:2 scroll:true lang:python decode:true plain:false\">q = EmployeePayTbl.objects.filter(emp_id__gte=311549902).values('date_hire')\nprint(q) <\/pre>\n<p>\u062d\u062a\u06cc \u0648\u0642\u062a\u06cc \u06a9\u0647 \u0641\u06cc\u0644\u062f query \u0631\u0627 \u067e\u0631\u06cc\u0646\u062a \u0628\u06af\u06cc\u0631\u06cc\u0645 \u062f\u0642\u06cc\u0642\u0627 SQL \u0628\u0627\u0644\u0627 \u067e\u0631\u06cc\u0646\u062a \u0645\u06cc \u0634\u0648\u062f:<\/p>\n<pre class=\"theme:sql font:liberation-mono font-size:14 nums:false line-height:20 toolbar:2 scroll:true lang:sql decode:true plain:false\">SELECT `EMPLOYEE_PAY_TBL`.`DATE_HIRE` FROM `EMPLOYEE_PAY_TBL` WHERE `EMPLOYEE_PAY_TBL`.`EMP_ID` &gt;= 311549902<\/pre>\n<p>\u0627\u0645\u0627 \u067e\u0627\u0631\u0627\u0645\u062a\u0631 \u062a\u0627\u0628\u0639 <em>filter<\/em> \u06a9\u0645\u06cc \u0639\u062c\u06cc\u0628 \u0628\u0647 \u0646\u0638\u0631 \u0645\u06cc\u200c\u0631\u0633\u062f \u0648 \u0628\u0647\u062a\u0631 \u0627\u0633\u062a \u062f\u0631 \u0622\u0646 \u062a\u0639\u0645\u0642 \u0634\u0648\u062f:<\/p>\n<p>\u0645\u062a\u0639\u06cc\u0631\u06cc \u06a9\u0647 \u0633\u0627\u062e\u062a\u0647 \u0634\u062f\u0647\u060c \u0627\u0632 \u062a\u0631\u06a9\u06cc\u0628 \u0627\u0633\u0645 \u0641\u06cc\u0644\u062f \u062f\u0631\u0648\u0646 \u0645\u062f\u0644 \u0648 \u062f\u0648 \u0640 \u0628\u0647 \u0647\u0645\u0631\u0627\u0647 \u062a\u0631\u06a9\u06cc\u0628 \u0639\u0645\u06af\u0631\u0647\u0627 \u0633\u0627\u062e\u062a\u0647 \u0634\u062f\u0647\u060c \u0647\u0645\u06cc\u0646 \u0645\u062b\u0627\u0644 \u0628\u0627\u0644\u0627 \u06cc\u0639\u0646\u06cc <em>emp_id__gte<\/em> \u0627\u0632 \u062a\u0631\u06a9\u06cc\u0628 emp_id \u0628\u0647 \u0639\u0644\u0627\u0648\u0647 \u062f\u0648 \u0640 \u0648 \u0628\u0647 \u0647\u0645\u0631\u0627\u0647 \u0639\u0645\u0644\u06af\u0631 \u0645\u0648\u0631\u062f \u0646\u0638\u0631 \u0627\u0633\u062a. \u0639\u0645\u0644\u06af\u0631 \u0645\u0648\u0631\u062f \u0646\u0638\u0631 \u06cc\u0639\u0646\u06cc Less Than Equal \u060c \u062f\u0631 SQL \u0645\u06cc\u200c\u0634\u0648\u062f =&gt; \u06a9\u0647 \u0628\u0647 \u0645\u0639\u0646\u0627\u06cc \u06a9\u0648\u0686\u06a9\u062a\u0631 \u0645\u0633\u0627\u0648\u06cc \u0627\u0633\u062a. \u062f\u0631\u0648\u0646 \u0622\u0646 \u0647\u0645 \u0645\u0633\u0627\u0648\u06cc \u062f\u06cc\u062f\u0647 \u0645\u06cc\u200c\u0634\u0648\u062f \u0648 \u0647\u0645 \u0645\u0642\u062f\u0627\u0631 \u0627\u06af\u0631 \u0628\u0647 \u06a9\u062f SQL \u0645\u0648\u0631\u062f \u0646\u0638\u0631 \u0646\u06af\u0627\u0647 \u06a9\u0646\u06cc\u062f\u060c \u06a9\u0627\u0645\u0644\u0627 \u062a\u0631\u06a9\u06cc\u0628 \u067e\u0627\u0631\u0627\u0645\u062a\u0631 <em>filter<\/em> \u062a\u0648\u0635\u06cc\u0641 \u0645\u06cc\u200c\u0634\u0648\u062f.<\/p>\n<p>\u0641\u0631\u0645\u062a\u06cc \u06a9\u0647 \u062a\u0627\u0628\u0639 <em>filter<\/em> \u062f\u0627\u0631\u062f \u0628\u0647 \u062f\u0648 \u062d\u0627\u0644\u062a \u0627\u0633\u062a:<\/p>\n<p>\u06f1. \u06cc\u0627 \u0645\u062a\u063a\u06cc\u0631 \u0628\u0647 \u0647\u0645\u0631\u0627\u0647 \u062f\u0648 \u0640 \u0648 \u0628\u0647 \u0647\u0645\u0631\u0627\u0647 \u06cc\u06a9 \u0639\u0645\u0644\u06af\u0631<\/p>\n<p>\u06f2. \u06cc\u0627 \u0645\u062a\u063a\u06cc\u0631 \u062a\u0646\u0647\u0627<\/p>\n<p>\u062a\u0627\u0628\u0639 \u0641\u06cc\u0644\u062a\u0631 \u0627\u0632 \u0639\u0645\u0644\u06af\u0631\u200c\u0647\u0627\u06cc \u0641\u0631\u062a\u0631\u0646\u06cc \u06a9\u0647 \u062f\u0631 \u0634\u0644 \u0627\u0633\u06a9\u0631\u06cc\u067e\u062a \u0647\u0645 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc\u200c\u0634\u0648\u0646\u062f \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc\u200c\u06a9\u0646\u062f:<\/p>\n<ul>\n<li>gt \u0628\u0647 \u0645\u0639\u0646\u0627\u06cc Great Than<\/li>\n<li>lt \u0628\u0647 \u0645\u0639\u0646\u0627\u06cc Less Than<\/li>\n<li>e \u0628\u0647 \u0645\u0639\u0646\u0627\u06cc Equal<\/li>\n<\/ul>\n<p>\u0627\u0644\u0628\u062a\u0647 \u062c\u0644\u0648\u062a\u0631 \u062a\u0631\u06a9\u06cc\u0628\u200c\u0647\u0627\u06cc \u0628\u06cc\u0634\u062a\u0631\u06cc \u0628\u0647 \u063a\u06cc\u0631 \u0627\u0632 \u062f\u0648 \u062a\u0631\u06a9\u06cc\u0628 \u0628\u0627\u0644\u0627 \u062e\u0648\u0627\u0647\u06cc\u0645 \u062f\u06cc\u062f.<\/p>\n<p><strong>\u0646\u06a9\u062a\u0647:<\/strong> \u0628\u0631\u0627\u06cc \u0645\u0633\u0627\u0648\u06cc \u0646\u06cc\u0627\u0632 \u0646\u06cc\u0633\u062a \u0627\u0632 \u06cc\u06a9 \u062a\u0631\u06a9\u06cc\u0628 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0646\u06cc\u0645\u060c \u0641\u0642\u0637 \u06a9\u0627\u0641\u06cc\u0633\u062a \u0627\u0633\u0645 \u0641\u06cc\u0644\u062f \u0646\u0648\u0634\u062a\u0647 \u0634\u062f.<\/p>\n<p>\u06cc\u06a9 \u0633\u0648\u0627\u0644\u06cc \u06a9\u0647 \u0647\u0645\u06cc\u0634\u0647 \u0645\u0637\u0631\u062d \u0627\u0633\u062a \u060c \u0686\u06af\u0648\u0646\u06af\u06cc \u0633\u0627\u062e\u062a AND , OR \u0648 NOT \u0645\u06cc\u200c\u0628\u0627\u0634\u062f. \u0628\u0631\u0627\u06cc \u0633\u0627\u062e\u062a\u0646 \u0627\u06cc\u0646 \u0633\u0647 \u0639\u0646\u0635\u0631 \u062c\u0646\u06af\u0648 \u062a\u0627\u0628\u0639 Q \u0631\u0627 \u0645\u0639\u0631\u0641\u06cc \u06a9\u0631\u062f\u0647 \u0627\u0633\u062a. \u0628\u0647 \u06a9\u062f \u0632\u06cc\u0631 \u062f\u0642\u062a \u06a9\u0646\u06cc\u062f:<\/p>\n<pre class=\"theme:python font:liberation-mono font-size:14 nums:true line-height:20 toolbar:2 scroll:true lang:python decode:true plain:false\">from django.db.models import Q\nq = EmployeePayTbl.objects.filter(~Q(emp_id__gte=311549902)).values('date_hire')\nprint(q)\n<\/pre>\n<p>\u062a\u0627\u0628\u0639 <em>Q<\/em> \u0647\u0645\u0627\u0646\u0646\u062f <em>filter<\/em> \u0634\u0631\u0637 \u0645\u06cc\u200c\u067e\u0630\u06cc\u0631\u062f. \u0628\u0627 \u0633\u0647 \u0639\u0645\u0644\u06af\u0631 \u0632\u06cc\u0631 \u0645\u06cc\u200c\u062a\u0648\u0627\u0646 NOT \u060c AND \u0648 OR \u0631\u0627 \u067e\u06cc\u0627\u062f\u0647\u200c\u0633\u0627\u0632\u06cc \u06a9\u0631\u062f:<\/p>\n<ul>\n<li>~ \u0628\u0647 \u0645\u0639\u0646\u06cc \u0639\u0645\u0644\u06af\u0631 NOT<\/li>\n<li>| \u0628\u0647 \u0645\u0639\u0646\u06cc \u0639\u0645\u0644\u06af\u0631 OR<\/li>\n<li>&amp; \u0628\u0647 \u0645\u0639\u0646\u06cc \u0639\u0645\u0644\u06af\u0631 AND<\/li>\n<\/ul>\n<pre class=\"theme:python font:liberation-mono font-size:14 nums:true line-height:20 toolbar:2 scroll:true lang:python decode:true plain:false\">from django.db.models import Q\nq = EmployeePayTbl.objects.filter(~Q(emp_id__gte=311549902) &amp; Q(position=\"SHIPPER\") ).values('date_hire')\nprint(q)\n<\/pre>\n<p>\u062f\u0631 \u06a9\u062f \u0628\u0627\u0644\u0627 \u0647\u0631 \u0686\u0647 emp_id \u06a9\u0647 \u0627\u0632 \u0639\u062f\u062f \u0641\u0648\u0642 \u0628\u0632\u0631\u06af\u062a\u0631 <em>\u0646\u0628\u0627\u0634\u062f <\/em>\u0631\u0627 \u0628\u0627 \u0647\u0631 row \u06cc \u06a9\u0647 position \u0622\u0646 \u0628\u0631\u0627\u0628\u0631 SHIPPER \u0628\u0627\u0634\u062f AND \u0645\u06cc\u200c\u06a9\u0646\u06cc\u0645\u060c \u0628\u0647 \u0637\u0648\u0631\u06cc \u06a9\u0647 \u062e\u0631\u0648\u062c\u06cc SQL \u0622\u0646 \u0628\u0647 \u0635\u0648\u0631\u062a \u0632\u06cc\u0631 \u0645\u06cc\u200c\u0634\u0648\u062f:<\/p>\n<pre class=\"theme:sql font:liberation-mono font-size:14 nums:false line-height:20 toolbar:2 scroll:true lang:sql decode:true plain:false\">SELECT `EMPLOYEE_PAY_TBL`.`DATE_HIRE` FROM `EMPLOYEE_PAY_TBL` WHERE (NOT (`EMPLOYEE_PAY_TBL`.`EMP_ID` &gt;= 311549902) AND `EMPLOYEE_PAY_TBL`.`POSITION` = SHIPPER)<\/pre>\n<p>\u062e\u0631\u0648\u062c\u06cc QuerySet \u0622\u0646 \u0646\u06cc\u0632 \u0628\u0647 \u0635\u0648\u0631\u062a \u0632\u06cc\u0631 \u0645\u06cc\u200c\u0634\u0648\u062f:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"theme:dark-terminal font:liberation-mono font-size:14 nums:false line-height:20 toolbar:2 scroll:true lang:sh decode:true plain:false\">&lt;QuerySet [{'date_hire': datetime.date(2006, 7, 22)}]&gt;<\/pre>\n<p><strong>\u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 LIKE:<\/strong><\/p>\n<p>\u0628\u0631\u0627\u06cc \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 LIKE \u060c \u0645\u06cc\u200c\u062a\u0648\u0627\u0646 \u0627\u0632 \u062a\u0631\u06a9\u06cc\u0628\u200c\u0647\u0627\u06cc \u0632\u06cc\u0631 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0646\u0645\u0648\u062f:<\/p>\n<ul>\n<li><code class=\"docutils literal notranslate\"><span class=\"pre\">contains<\/span><\/code><\/li>\n<li>i<code class=\"docutils literal notranslate\"><span class=\"pre\">contains<\/span><\/code><\/li>\n<li><code class=\"docutils literal notranslate\"><span class=\"pre\">startswith<\/span><\/code><\/li>\n<li>i<code class=\"docutils literal notranslate\"><span class=\"pre\">startswith<\/span><\/code><\/li>\n<li><code class=\"docutils literal notranslate\"><span class=\"pre\">endswith<\/span><\/code><\/li>\n<li>i<code class=\"docutils literal notranslate\"><span class=\"pre\">endswith<\/span><\/code><\/li>\n<li>exact<\/li>\n<li>iexact<\/li>\n<\/ul>\n<p><strong>\u0646\u06a9\u062a\u0647:<\/strong>&nbsp; \u0648\u0642\u062a\u06cc \u0627\u0632 i \u062f\u0631 \u0627\u0648\u0644 \u0647\u0631 \u06a9\u062f\u0627\u0645 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc\u200c\u0634\u0648\u062f \u0628\u0647 \u0645\u0639\u0646\u06cc <em>case-insensitive<\/em> \u0645\u06cc\u200c\u0628\u0627\u0634\u062f.<\/p>\n<p>\u0628\u0647 \u062a\u06a9\u0647 \u06a9\u062f\u200c\u0647\u0627\u06cc \u0632\u06cc\u0631 \u0648 SQL \u0645\u0648\u062c\u0648\u062f \u062f\u0631 \u0632\u06cc\u0631 \u0622\u0646 \u062f\u0642\u062a \u06a9\u0646\u06cc\u062f:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"theme:python font:liberation-mono font-size:14 nums:true line-height:20 toolbar:2 scroll:true lang:python decode:true plain:false\">q = EmployeePayTbl.objects.filter(position__contains=\"P\" ).values('position')<\/pre>\n<pre class=\"theme:sql font:liberation-mono font-size:14 nums:false line-height:20 toolbar:2 scroll:true lang:sql decode:true plain:false\">SELECT `EMPLOYEE_PAY_TBL`.`POSITION` FROM `EMPLOYEE_PAY_TBL` WHERE `EMPLOYEE_PAY_TBL`.`POSITION` LIKE BINARY %P%<\/pre>\n<p>\u062f\u0631 \u06a9\u062f \u0628\u0627\u0644\u0627 \u0627\u0632 %mystring% \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0634\u062f.<\/p>\n<pre class=\"theme:python font:liberation-mono font-size:14 nums:true line-height:20 toolbar:2 scroll:true lang:python decode:true plain:false\">q = EmployeePayTbl.objects.filter(position__startswith=\"S\" ).values('position')<\/pre>\n<pre class=\"theme:sql font:liberation-mono font-size:14 nums:false line-height:20 toolbar:2 scroll:true lang:sql decode:true plain:false\">SELECT `EMPLOYEE_PAY_TBL`.`POSITION` FROM `EMPLOYEE_PAY_TBL` WHERE `EMPLOYEE_PAY_TBL`.`POSITION` LIKE BINARY S%<\/pre>\n<p>\u062f\u0631 \u06a9\u062f \u0628\u0627\u0644\u0627 \u0647\u0631 \u0631\u0634\u062a\u0647\u200c\u0627\u06cc \u06a9\u0647 \u0628\u0627 \u062d\u0631\u0641 s \u0634\u0631\u0648\u0639 \u0645\u06cc\u200c\u0634\u0648\u062f \u0645\u062f \u0646\u0638\u0631 \u0627\u0633\u062a.<\/p>\n<pre class=\"theme:python font:liberation-mono font-size:14 nums:true line-height:20 toolbar:2 scroll:true lang:python decode:true plain:false\">q = EmployeePayTbl.objects.filter(position__endswith=\"N\" ).values('position')<\/pre>\n<pre class=\"theme:sql font:liberation-mono font-size:14 nums:false line-height:20 toolbar:2 scroll:true lang:sql decode:true plain:false\">SELECT `EMPLOYEE_PAY_TBL`.`POSITION` FROM `EMPLOYEE_PAY_TBL` WHERE `EMPLOYEE_PAY_TBL`.`POSITION` LIKE BINARY %N<\/pre>\n<p>\u062f\u0631 \u06a9\u062f \u0628\u0627\u0644\u0627 \u0647\u0631 \u0631\u0634\u062a\u0647\u200c\u0627\u06cc \u06a9\u0647 \u0628\u0627 \u062d\u0631\u0641 N&nbsp; \u062e\u0627\u062a\u0645\u0647 \u0645\u06cc\u200c\u06cc\u0627\u0628\u062f \u0645\u062f \u0646\u0638\u0631 \u0627\u0633\u062a.<\/p>\n<pre class=\"theme:python font:liberation-mono font-size:14 nums:true line-height:20 toolbar:2 scroll:true lang:python decode:true plain:false\">q = EmployeePayTbl.objects.filter(position__exact=\"SHIPPER\" ).values('position')<\/pre>\n<pre class=\"theme:sql font:liberation-mono font-size:14 nums:false line-height:20 toolbar:2 scroll:true lang:sql decode:true plain:false\">SELECT `EMPLOYEE_PAY_TBL`.`POSITION` FROM `EMPLOYEE_PAY_TBL` WHERE `EMPLOYEE_PAY_TBL`.`POSITION` = SHIPPER<\/pre>\n<p>\u062f\u0631 \u06a9\u062f \u0628\u0627\u0644\u0627 \u0639\u0645\u0644\u06af\u0631 \u062a\u0633\u0627\u0648\u06cc \u0645\u0647\u0645 \u0627\u0633\u062a.<\/p>\n<p><strong>\u0646\u06a9\u062a\u0647:<\/strong> \u0628\u0631\u0627\u06cc NOT \u06a9\u0631\u062f\u0646 \u0647\u0631 \u06a9\u062f\u0627\u0645 \u0627\u0632 Query \u0647\u0627\u06cc \u0628\u0627\u0644\u0627 \u0645\u06cc\u200c\u062a\u0648\u0627\u0646\u06cc\u062f \u0627\u0632 \u062a\u0627\u0628\u0639 <em>Q<\/em> \u0628\u0647 \u0635\u0648\u0631\u062a\u06cc \u06a9\u0647 \u0642\u0628\u0644\u200c\u062a\u0631 \u06af\u0641\u062a\u0647 \u0634\u062f \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0646\u06cc\u062f.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><strong>\u0645\u0637\u0627\u0644\u0628 \u0645\u0631\u0628\u0648\u0637 \u0628\u0647 ORM \u062c\u0646\u06af\u0648 \u0627\u062f\u0627\u0645\u0647 \u062e\u0648\u0627\u0647\u0646\u062f \u062f\u0627\u0634\u062a. \u0645\u0646\u062a\u0638\u0631 \u0628\u0627\u0634\u06cc\u062f.<\/strong><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u062f\u0631 \u0627\u06cc\u0646 \u0642\u0633\u0645\u062a \u0633\u0639\u06cc \u0628\u0631 \u0622\u0646 \u062f\u0627\u0631\u06cc\u0645 \u062a\u0627 \u0639\u0645\u0644\u06af\u0631\u0647\u0627\u06cc \u0627\u0635\u0644\u06cc \u06a9\u0647 \u062f\u0631 SELECT \u0646\u0648\u0634\u062a\u0647 \u0645\u06cc\u200c\u0634\u0648\u062f \u0631\u0627 \u062f\u0631 Django \u0628\u0646\u0648\u06cc\u0633\u06cc\u0645. \u0633\u0639\u06cc \u0628\u0631 \u0622\u0646 \u0627\u0633\u062a \u062a\u0627 \u0628\u0627 \u0645\u062b\u0627\u0644\u200c\u0647\u0627\u06cc\u06cc \u0628\u062a\u0648\u0627\u0646 \u0633\u0631\u0639\u062a \u0628\u0627\u0644\u0627\u06cc \u06a9\u0627\u0631 \u0628\u0627 \u0627\u06cc\u0646 ORM \u0631\u0627 \u0628\u0631\u0631\u0633\u06cc \u06a9\u0631\u062f. \u0633\u0639\u06cc \u0634\u062f\u0647 \u062a\u0627 \u0644\u06cc\u0633\u062a\u06cc \u0627\u0632 \u0639\u0645\u0644\u06af\u0631\u0647\u0627\u06cc WHERE \u0628\u0631\u0631\u0633\u06cc \u0634\u0648\u0646\u062f. \u0628\u0631\u0627\u06cc \u06a9\u0627\u0631 \u0628\u0627 \u0639\u0645\u0644\u06af\u0631\u0647\u0627 \u062f\u0631 \u0627\u0628\u062a\u062f\u0627 \u0646\u06cc\u0627\u0632 \u0627\u0633\u062a \u0645\u062b\u0627\u0644\u200c\u0647\u0627\u06cc \u06a9\u0648\u0686\u06a9\u06cc &hellip; <a href=\"https:\/\/pahlevanzadeh.net\/?p=962\" class=\"more-link\">\u0627\u062f\u0627\u0645\u0647 \u062e\u0648\u0627\u0646\u062f\u0646 <span class=\"screen-reader-text\">\u0646\u0648\u0634\u062a\u0646 Query \u0647\u0627\u06cc SQL \u0628\u0627 Django (\u0642\u0633\u0645\u062a \u062f\u0648\u0645[\u0646\u06af\u0627\u0647\u06cc \u0628\u0647 \u0639\u0645\u0644\u06af\u0631\u200c\u0647\u0627\u06cc SQL])<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[110],"tags":[337,349,350,352,338,346,343,66,348,351],"_links":{"self":[{"href":"https:\/\/pahlevanzadeh.net\/index.php?rest_route=\/wp\/v2\/posts\/962"}],"collection":[{"href":"https:\/\/pahlevanzadeh.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pahlevanzadeh.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pahlevanzadeh.net\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/pahlevanzadeh.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=962"}],"version-history":[{"count":54,"href":"https:\/\/pahlevanzadeh.net\/index.php?rest_route=\/wp\/v2\/posts\/962\/revisions"}],"predecessor-version":[{"id":1023,"href":"https:\/\/pahlevanzadeh.net\/index.php?rest_route=\/wp\/v2\/posts\/962\/revisions\/1023"}],"wp:attachment":[{"href":"https:\/\/pahlevanzadeh.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pahlevanzadeh.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=962"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pahlevanzadeh.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}