<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5356089030550857026</id><updated>2026-11-18T19:30:00.191-08:00</updated><category term="Interview"/><category term="ASP.NET"/><category term="C#"/><category term="Sql"/><category term="C Sharp"/><category term="General"/><category term="Azure"/><category term="WCF"/><category term="GridView"/><category term="Javascript"/><category term="Ajax"/><category term="JQuery"/><category term="MVC"/><category term="Linq"/><category term="ADO.NET"/><category term="C Tips"/><category term="Collection"/><category term="WebService"/><category term="XML"/><category term="AI"/><category term="DropDown"/><category term="FileUpload"/><category term="Gen AI"/><category term="LLM"/><category term="ReactJs"/><category term="API"/><category term="Crystal Report"/><category term="EntityFramework"/><category term="Error"/><category term="GoogleMap"/><category term="Mail"/><category term="ReactJs Inteview Questions"/><category term="Report"/><category term="SSRS"/><category term="Angular"/><category term="Angular Error"/><category term="Angular2"/><category term="Bootstrap"/><category term="Excel"/><category term="Exception"/><category term="IIS"/><category term="ListView"/><category term="Project"/><category term="Translator"/><category term="VS Error"/><category term="Validation"/><category term="web.config"/><title type='text'>DotNet and AI Materials</title><subtitle type='html'>This blog will guid you to upskill youself in Microsoft Technology like c#,Dotnet Core, Web API, MS SQL, Azure, Gen AI, RAg, AI, LLm and Interview Preparation.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>330</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-1603133790210480353</id><published>2026-11-18T19:30:00.000-08:00</published><updated>2026-11-18T19:30:00.186-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Calculate the moving average of salaries over the last 3 employees ordered by hire date.</title><content type='html'>Let&#39;s create table schema and sample data first.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Table Schema and sample:-&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;TABLE&lt;/span&gt; &lt;span style=&quot;color: #0051c2;&quot;&gt;employees&lt;/span&gt; (&lt;/div&gt;&lt;div&gt;&amp;nbsp;
id        &lt;span style=&quot;color: #8100c2;&quot;&gt;INT&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;PRIMARY KEY&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;  &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;      &lt;span style=&quot;color: #8100c2;&quot;&gt;VARCHAR&lt;/span&gt;(&lt;span style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;) &lt;span style=&quot;color: #8100c2;&quot;&gt;NOT NULL&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;  hire_date &lt;span style=&quot;color: #8100c2;&quot;&gt;DATE&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;NOT NULL&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;  salary    &lt;span style=&quot;color: #8100c2;&quot;&gt;DECIMAL&lt;/span&gt;(&lt;span style=&quot;color: teal;&quot;&gt;10&lt;/span&gt;,&lt;span style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;)&amp;nbsp;&lt;/div&gt;&lt;div&gt;);&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;
&lt;span style=&quot;color: #8100c2;&quot;&gt;INSERT INTO&lt;/span&gt; employees (id, &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;, hire_date, salary) &lt;span style=&quot;color: #8100c2;&quot;&gt;VALUES&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Asha&#39;&lt;/span&gt;,  &lt;span style=&quot;color: green;&quot;&gt;&#39;2024-01-15&#39;&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;50000&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Ravi&#39;&lt;/span&gt;,  &lt;span style=&quot;color: green;&quot;&gt;&#39;2024-03-10&#39;&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;60000&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Meera&#39;&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;2024-05-20&#39;&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;70000&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Kiran&#39;&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;2024-08-01&#39;&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;80000&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;5&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Neha&#39;&lt;/span&gt;,  &lt;span style=&quot;color: green;&quot;&gt;&#39;2025-01-12&#39;&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;90000&lt;/span&gt;),&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;6&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Rohan&#39;&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;2025-06-30&#39;&lt;/span&gt;, &lt;span style=&quot;color: teal;&quot;&gt;100000&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Query(MS SQL):-&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;SELECT&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;id,&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;hire_date, salary,&amp;nbsp;&lt;/div&gt;&lt;div&gt;       &lt;span style=&quot;color: #0051c2;&quot;&gt;AVG&lt;/span&gt;(salary) &lt;span style=&quot;color: #8100c2;&quot;&gt;OVER&lt;/span&gt; (
         &lt;span style=&quot;color: #8100c2;&quot;&gt;ORDER BY&lt;/span&gt; hire_date, id
         &lt;span style=&quot;color: #8100c2;&quot;&gt;ROWS&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;BETWEEN&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;PRECEDING&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;AND&lt;/span&gt; CURRENT &lt;span style=&quot;color: #8100c2;&quot;&gt;ROW&lt;/span&gt;
       ) &lt;span style=&quot;color: #8100c2;&quot;&gt;AS&lt;/span&gt; moving_avg_3&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;FROM&lt;/span&gt; employees&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;ORDER BY&lt;/span&gt; hire_date, id;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/1603133790210480353/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/calculate-moving-average-of-salaries.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/1603133790210480353'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/1603133790210480353'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/calculate-moving-average-of-salaries.html' title='Calculate the moving average of salaries over the last 3 employees ordered by hire date.'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-5027457256862217078</id><published>2026-11-17T19:30:00.000-08:00</published><updated>2026-11-17T19:30:00.121-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Write a query to perform a self-join to find pairs of employees in the same department.</title><content type='html'>Let&#39;s create Table schema and sample data first, then will write query to fetch data.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Table Schema and Sample data:-&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;TABLE&lt;/span&gt; &lt;span style=&quot;color: #0051c2;&quot;&gt;departments&lt;/span&gt; (&amp;nbsp;&lt;/div&gt;&lt;div&gt;  id   &lt;span style=&quot;color: #8100c2;&quot;&gt;INT&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;PRIMARY KEY&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;  &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;VARCHAR&lt;/span&gt;(&lt;span style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;) &lt;span style=&quot;color: #8100c2;&quot;&gt;NOT NULL&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;);&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;
&lt;span style=&quot;color: #8100c2;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;TABLE&lt;/span&gt; &lt;span style=&quot;color: #0051c2;&quot;&gt;employees&lt;/span&gt; (&lt;/div&gt;&lt;div&gt;&amp;nbsp;
id            &lt;span style=&quot;color: #8100c2;&quot;&gt;INT&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;PRIMARY KEY&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;  &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;          &lt;span style=&quot;color: #8100c2;&quot;&gt;VARCHAR&lt;/span&gt;(&lt;span style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;) &lt;span style=&quot;color: #8100c2;&quot;&gt;NOT NULL&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;  department_id &lt;span style=&quot;color: #8100c2;&quot;&gt;INT&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;  &lt;span style=&quot;color: #8100c2;&quot;&gt;FOREIGN KEY&lt;/span&gt; (department_id) &lt;span style=&quot;color: #8100c2;&quot;&gt;REFERENCES&lt;/span&gt; departments(id)&amp;nbsp;&lt;/div&gt;&lt;div&gt;);&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;
&lt;span style=&quot;color: #8100c2;&quot;&gt;INSERT INTO&lt;/span&gt; departments (id, &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;) &lt;span style=&quot;color: #8100c2;&quot;&gt;VALUES&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;10&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Engineering&#39;&lt;/span&gt;),
(&lt;span style=&quot;color: teal;&quot;&gt;20&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Sales&#39;&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;30&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;HR&#39;&lt;/span&gt;);&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;
&lt;span style=&quot;color: #8100c2;&quot;&gt;INSERT INTO&lt;/span&gt; employees (id, &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;, department_id) &lt;span style=&quot;color: #8100c2;&quot;&gt;VALUES&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Asha&#39;&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;10&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Ravi&#39;&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;10&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Meera&#39;&lt;/span&gt;, &lt;span style=&quot;color: teal;&quot;&gt;10&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Kiran&#39;&lt;/span&gt;, &lt;span style=&quot;color: teal;&quot;&gt;20&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;5&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Neha&#39;&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;20&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;6&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Rohan&#39;&lt;/span&gt;, &lt;span style=&quot;color: teal;&quot;&gt;30&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;7&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Tara&#39;&lt;/span&gt;,  &lt;span style=&quot;color: #8100c2;&quot;&gt;NULL&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Query(MS SQL):-&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;SELECT&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;e1.name &lt;span style=&quot;color: #8100c2;&quot;&gt;AS&lt;/span&gt; employee_1,&amp;nbsp;&lt;/div&gt;&lt;div&gt;       e2.name &lt;span style=&quot;color: #8100c2;&quot;&gt;AS&lt;/span&gt; employee_2,&amp;nbsp;&lt;/div&gt;&lt;div&gt;       e1.department_id&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;FROM&lt;/span&gt; employees e1&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;JOIN&lt;/span&gt; employees e2&amp;nbsp;&lt;/div&gt;&lt;div&gt;  &lt;span style=&quot;color: #8100c2;&quot;&gt;ON&lt;/span&gt; e1.department_id = e2.department_id&amp;nbsp;&lt;/div&gt;&lt;div&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;AND&lt;/span&gt; e1.id &amp;lt; e2.id&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;ORDER BY&lt;/span&gt; e1.department_id, e1.id, e2.id;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/5027457256862217078/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/write-query-to-perform-self-join-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/5027457256862217078'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/5027457256862217078'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/write-query-to-perform-self-join-to.html' title='Write a query to perform a self-join to find pairs of employees in the same department.'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-2637741573429621235</id><published>2026-11-16T19:30:00.000-08:00</published><updated>2026-11-16T19:30:00.174-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Write a query to find the difference in days between two dates in the same table.</title><content type='html'>Let&#39;s create&amp;nbsp; table schema and sample data.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Table schema and sample data:-&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;TABLE&lt;/span&gt; &lt;span style=&quot;color: #0051c2;&quot;&gt;orders&lt;/span&gt; (&lt;/div&gt;&lt;div&gt;&amp;nbsp;
order_id   &lt;span style=&quot;color: #8100c2;&quot;&gt;INT&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;PRIMARY KEY&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;  order_date &lt;span style=&quot;color: #8100c2;&quot;&gt;DATE&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;NOT NULL&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;  ship_date  &lt;span style=&quot;color: #8100c2;&quot;&gt;DATE&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;);&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;
&lt;span style=&quot;color: #8100c2;&quot;&gt;INSERT INTO&lt;/span&gt; orders (order_id, order_date, ship_date) &lt;span style=&quot;color: #8100c2;&quot;&gt;VALUES&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;2026-10-01&#39;&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;2026-10-05&#39;&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;2026-10-10&#39;&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;2026-10-10&#39;&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;2026-09-28&#39;&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;2026-10-12&#39;&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;2026-10-15&#39;&lt;/span&gt;, &lt;span style=&quot;color: #8100c2;&quot;&gt;NULL&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;5&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;2026-10-20&#39;&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;2026-10-18&#39;&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Query(MS SQL):-&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;SELECT&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;order_id,&amp;nbsp;&lt;/div&gt;&lt;div&gt;order_date,&amp;nbsp;&lt;/div&gt;&lt;div&gt;ship_date,&amp;nbsp;&lt;/div&gt;&lt;div&gt;       &lt;span style=&quot;color: #0051c2;&quot;&gt;DATEDIFF&lt;/span&gt;(&lt;span style=&quot;color: #8100c2;&quot;&gt;DAY&lt;/span&gt;, order_date, ship_date) &lt;span style=&quot;color: #8100c2;&quot;&gt;AS&lt;/span&gt; days_to_ship&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;FROM&lt;/span&gt; orders;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/2637741573429621235/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/write-query-to-find-difference-in-days.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/2637741573429621235'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/2637741573429621235'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/write-query-to-find-difference-in-days.html' title='Write a query to find the difference in days between two dates in the same table.'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-5326682957548878557</id><published>2026-11-15T19:30:00.000-08:00</published><updated>2026-11-15T19:30:00.274-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Find employees who don’t have a department assigned.</title><content type='html'>Let&#39;s create table schema and sample data.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Table Schema and sample data:-&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;TABLE&lt;/span&gt; &lt;span style=&quot;color: #0051c2;&quot;&gt;departments&lt;/span&gt; (&lt;/div&gt;&lt;div&gt;&amp;nbsp;
id   &lt;span style=&quot;color: #8100c2;&quot;&gt;INT&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;PRIMARY KEY&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;  &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;VARCHAR&lt;/span&gt;(&lt;span style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;) &lt;span style=&quot;color: #8100c2;&quot;&gt;NOT NULL&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;);&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;
&lt;span style=&quot;color: #8100c2;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;TABLE&lt;/span&gt; &lt;span style=&quot;color: #0051c2;&quot;&gt;employees&lt;/span&gt; (&lt;/div&gt;&lt;div&gt;&amp;nbsp;
id            &lt;span style=&quot;color: #8100c2;&quot;&gt;INT&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;PRIMARY KEY&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;  &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;          &lt;span style=&quot;color: #8100c2;&quot;&gt;VARCHAR&lt;/span&gt;(&lt;span style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;) &lt;span style=&quot;color: #8100c2;&quot;&gt;NOT NULL&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;  department_id &lt;span style=&quot;color: #8100c2;&quot;&gt;INT&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;  &lt;span style=&quot;color: #8100c2;&quot;&gt;FOREIGN KEY&lt;/span&gt; (department_id) &lt;span style=&quot;color: #8100c2;&quot;&gt;REFERENCES&lt;/span&gt; departments(id)&amp;nbsp;&lt;/div&gt;&lt;div&gt;);&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;
&lt;span style=&quot;color: #8100c2;&quot;&gt;INSERT INTO&lt;/span&gt; departments (id, &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;) &lt;span style=&quot;color: #8100c2;&quot;&gt;VALUES&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;10&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Engineering&#39;&lt;/span&gt;),
(&lt;span style=&quot;color: teal;&quot;&gt;20&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Sales&#39;&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;30&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;HR&#39;&lt;/span&gt;);&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;
&lt;span style=&quot;color: #8100c2;&quot;&gt;INSERT INTO&lt;/span&gt; employees (id, &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;, department_id) &lt;span style=&quot;color: #8100c2;&quot;&gt;VALUES&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Asha&#39;&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;10&lt;/span&gt;),
(&lt;span style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Ravi&#39;&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;20&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Meera&#39;&lt;/span&gt;, &lt;span style=&quot;color: #8100c2;&quot;&gt;NULL&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Kiran&#39;&lt;/span&gt;, &lt;span style=&quot;color: teal;&quot;&gt;30&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;5&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Neha&#39;&lt;/span&gt;,  &lt;span style=&quot;color: #8100c2;&quot;&gt;NULL&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Query:-&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;SELECT&lt;/span&gt; *&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;FROM&lt;/span&gt; employees&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;WHERE&lt;/span&gt; department_id &lt;span style=&quot;color: #8100c2;&quot;&gt;IS&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;NULL&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/5326682957548878557/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/find-employees-who-dont-have-department.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/5326682957548878557'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/5326682957548878557'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/find-employees-who-dont-have-department.html' title='Find employees who don’t have a department assigned.'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-3076719816274262311</id><published>2026-11-14T19:30:00.000-08:00</published><updated>2026-11-14T19:30:00.175-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Write a query to find the number of employees in each job title.</title><content type='html'>Let&#39;s create table schema and sample data.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Table Schema and Sample data:-&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;TABLE&lt;/span&gt; &lt;span style=&quot;color: #0051c2;&quot;&gt;employees&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&amp;nbsp;&lt;/div&gt;&lt;div&gt;  id        &lt;span style=&quot;color: #8100c2;&quot;&gt;INT&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;PRIMARY KEY&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;  &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;      &lt;span style=&quot;color: #8100c2;&quot;&gt;VARCHAR&lt;/span&gt;(&lt;span style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;) &lt;span style=&quot;color: #8100c2;&quot;&gt;NOT NULL&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;  job_title &lt;span style=&quot;color: #8100c2;&quot;&gt;VARCHAR&lt;/span&gt;(&lt;span style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;)&amp;nbsp;&lt;/div&gt;&lt;div&gt;);&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;
&lt;span style=&quot;color: #8100c2;&quot;&gt;INSERT INTO&lt;/span&gt; employees (id, &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;, job_title)&amp;nbsp;&lt;span style=&quot;color: #8100c2;&quot;&gt;VALUES&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Asha&#39;&lt;/span&gt;,  &lt;span style=&quot;color: green;&quot;&gt;&#39;Software Engineer&#39;&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Ravi&#39;&lt;/span&gt;,  &lt;span style=&quot;color: green;&quot;&gt;&#39;Software Engineer&#39;&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Meera&#39;&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Sales Executive&#39;&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Kiran&#39;&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Sales Executive&#39;&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;5&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Neha&#39;&lt;/span&gt;,  &lt;span style=&quot;color: green;&quot;&gt;&#39;Sales Executive&#39;&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;6&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Rohan&#39;&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;HR Manager&#39;&lt;/span&gt;),&amp;nbsp;&lt;/div&gt;&lt;div&gt;(&lt;span style=&quot;color: teal;&quot;&gt;7&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Tara&#39;&lt;/span&gt;,  &lt;span style=&quot;color: #8100c2;&quot;&gt;NULL&lt;/span&gt;);&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Query:-&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;SELECT&lt;/span&gt; job_title,&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #0051c2;&quot;&gt;COUNT&lt;/span&gt;(*) &lt;span style=&quot;color: #8100c2;&quot;&gt;AS&lt;/span&gt; employee_count&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;FROM&lt;/span&gt; employees&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;GROUP BY&lt;/span&gt; job_title&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;ORDER BY&lt;/span&gt; employee_count &lt;span style=&quot;color: #8100c2;&quot;&gt;DESC&lt;/span&gt;;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/3076719816274262311/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/write-query-to-find-number-of-employees.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/3076719816274262311'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/3076719816274262311'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/write-query-to-find-number-of-employees.html' title='Write a query to find the number of employees in each job title.'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-6917629587640037673</id><published>2026-11-13T19:30:00.000-08:00</published><updated>2026-11-13T19:30:00.169-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Find departments with the highest average salary.</title><content type='html'>&lt;p&gt;Let&#39;s create table schema and sample data first, after that will write query.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Table Schema and Sample Data:-&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;TABLE&lt;/span&gt; &lt;span style=&quot;color: #0051c2;&quot;&gt;departments&lt;/span&gt; (
  id   &lt;span style=&quot;color: #8100c2;&quot;&gt;INT&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;PRIMARY KEY&lt;/span&gt;,
  &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;VARCHAR&lt;/span&gt;(&lt;span style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;) &lt;span style=&quot;color: #8100c2;&quot;&gt;NOT NULL&lt;/span&gt;
);

&lt;span style=&quot;color: #8100c2;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;TABLE&lt;/span&gt; &lt;span style=&quot;color: #0051c2;&quot;&gt;employees&lt;/span&gt; (
  id            &lt;span style=&quot;color: #8100c2;&quot;&gt;INT&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;PRIMARY KEY&lt;/span&gt;,
  &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;          &lt;span style=&quot;color: #8100c2;&quot;&gt;VARCHAR&lt;/span&gt;(&lt;span style=&quot;color: teal;&quot;&gt;50&lt;/span&gt;) &lt;span style=&quot;color: #8100c2;&quot;&gt;NOT NULL&lt;/span&gt;,
  department_id &lt;span style=&quot;color: #8100c2;&quot;&gt;INT&lt;/span&gt;,
  salary        &lt;span style=&quot;color: #8100c2;&quot;&gt;DECIMAL&lt;/span&gt;(&lt;span style=&quot;color: teal;&quot;&gt;10&lt;/span&gt;,&lt;span style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;),
  &lt;span style=&quot;color: #8100c2;&quot;&gt;FOREIGN KEY&lt;/span&gt; (department_id) &lt;span style=&quot;color: #8100c2;&quot;&gt;REFERENCES&lt;/span&gt; departments(id)
);

&lt;span style=&quot;color: #8100c2;&quot;&gt;INSERT INTO&lt;/span&gt; departments (id, &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;) &lt;span style=&quot;color: #8100c2;&quot;&gt;VALUES&lt;/span&gt;
(&lt;span style=&quot;color: teal;&quot;&gt;10&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Engineering&#39;&lt;/span&gt;),
(&lt;span style=&quot;color: teal;&quot;&gt;20&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Sales&#39;&lt;/span&gt;),
(&lt;span style=&quot;color: teal;&quot;&gt;30&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;HR&#39;&lt;/span&gt;),
(&lt;span style=&quot;color: teal;&quot;&gt;40&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Finance&#39;&lt;/span&gt;);

&lt;span style=&quot;color: #8100c2;&quot;&gt;INSERT INTO&lt;/span&gt; employees (id, &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;, department_id, salary) &lt;span style=&quot;color: #8100c2;&quot;&gt;VALUES&lt;/span&gt;
(&lt;span style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Asha&#39;&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;10&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;95000&lt;/span&gt;),
(&lt;span style=&quot;color: teal;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Ravi&#39;&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;10&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;85000&lt;/span&gt;),
(&lt;span style=&quot;color: teal;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Meera&#39;&lt;/span&gt;, &lt;span style=&quot;color: teal;&quot;&gt;20&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;60000&lt;/span&gt;),
(&lt;span style=&quot;color: teal;&quot;&gt;4&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Kiran&#39;&lt;/span&gt;, &lt;span style=&quot;color: teal;&quot;&gt;20&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;70000&lt;/span&gt;),
(&lt;span style=&quot;color: teal;&quot;&gt;5&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Neha&#39;&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;30&lt;/span&gt;,  &lt;span style=&quot;color: teal;&quot;&gt;80000&lt;/span&gt;),
(&lt;span style=&quot;color: teal;&quot;&gt;6&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Rohan&#39;&lt;/span&gt;, &lt;span style=&quot;color: teal;&quot;&gt;30&lt;/span&gt;, &lt;span style=&quot;color: teal;&quot;&gt;100000&lt;/span&gt;),
(&lt;span style=&quot;color: teal;&quot;&gt;7&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;&#39;Tara&#39;&lt;/span&gt;,  &lt;span style=&quot;color: #8100c2;&quot;&gt;NULL&lt;/span&gt;, &lt;span style=&quot;color: teal;&quot;&gt;120000&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The averages are Engineering 90000, HR 90000, and Sales 65000. Finance has no employees. Engineering and HR are tied for the highest, and Tara has no department.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Query 1: Order and take the top row&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;SELECT&lt;/span&gt; d.name, &lt;span style=&quot;color: #0051c2;&quot;&gt;AVG&lt;/span&gt;(e.salary) &lt;span style=&quot;color: #8100c2;&quot;&gt;AS&lt;/span&gt; avg_salary
&lt;span style=&quot;color: #8100c2;&quot;&gt;FROM&lt;/span&gt; departments d
&lt;span style=&quot;color: #8100c2;&quot;&gt;JOIN&lt;/span&gt; employees e &lt;span style=&quot;color: #8100c2;&quot;&gt;ON&lt;/span&gt; e.department_id = d.id
&lt;span style=&quot;color: #8100c2;&quot;&gt;GROUP BY&lt;/span&gt; d.id, d.name
&lt;span style=&quot;color: #8100c2;&quot;&gt;ORDER BY&lt;/span&gt; avg_salary &lt;span style=&quot;color: #8100c2;&quot;&gt;DESC&lt;/span&gt;
&lt;span style=&quot;color: #8100c2;&quot;&gt;LIMIT&lt;/span&gt; &lt;span style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Use &lt;code&gt;SELECT TOP 1 ...&lt;/code&gt; in SQL Server, or &lt;code&gt;FETCH FIRST 1 ROW ONLY&lt;/code&gt; in Oracle. This returns only &lt;strong&gt;one&lt;/strong&gt; row, so with our tie it shows either Engineering or HR, and which one is not guaranteed. Add a tie-breaker such as &lt;code&gt;ORDER BY avg_salary DESC, d.name&lt;/code&gt; if you want a predictable pick.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Query 2: Return every department tied for the highest (recommended)&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;WITH&lt;/span&gt; dept_avg &lt;span style=&quot;color: #8100c2;&quot;&gt;AS&lt;/span&gt; (
  &lt;span style=&quot;color: #8100c2;&quot;&gt;SELECT&lt;/span&gt; d.id, d.name, &lt;span style=&quot;color: #0051c2;&quot;&gt;AVG&lt;/span&gt;(e.salary) &lt;span style=&quot;color: #8100c2;&quot;&gt;AS&lt;/span&gt; avg_salary
  &lt;span style=&quot;color: #8100c2;&quot;&gt;FROM&lt;/span&gt; departments d
  &lt;span style=&quot;color: #8100c2;&quot;&gt;JOIN&lt;/span&gt; employees e &lt;span style=&quot;color: #8100c2;&quot;&gt;ON&lt;/span&gt; e.department_id = d.id
  &lt;span style=&quot;color: #8100c2;&quot;&gt;GROUP BY&lt;/span&gt; d.id, d.name
)
&lt;span style=&quot;color: #8100c2;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;, avg_salary
&lt;span style=&quot;color: #8100c2;&quot;&gt;FROM&lt;/span&gt; dept_avg
&lt;span style=&quot;color: #8100c2;&quot;&gt;WHERE&lt;/span&gt; avg_salary = (&lt;span style=&quot;color: #8100c2;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #0051c2;&quot;&gt;MAX&lt;/span&gt;(avg_salary) &lt;span style=&quot;color: #8100c2;&quot;&gt;FROM&lt;/span&gt; dept_avg);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Result:-&lt;/strong&gt;&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;th&gt;avg_salary&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Engineering&lt;/td&gt;
&lt;td&gt;90000.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HR&lt;/td&gt;
&lt;td&gt;90000.00&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;How it works&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The CTE &lt;code&gt;dept_avg&lt;/code&gt; calculates one average per department.&lt;/li&gt;
&lt;li&gt;The subquery &lt;code&gt;SELECT MAX(avg_salary) FROM dept_avg&lt;/code&gt; finds the highest of those averages.&lt;/li&gt;
&lt;li&gt;The outer query keeps every department whose average equals that maximum, so ties are all returned.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Query 3: Window function (easy to extend to the top N)&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;WITH&lt;/span&gt; dept_avg &lt;span style=&quot;color: #8100c2;&quot;&gt;AS&lt;/span&gt; (
  &lt;span style=&quot;color: #8100c2;&quot;&gt;SELECT&lt;/span&gt; d.id, d.name, &lt;span style=&quot;color: #0051c2;&quot;&gt;AVG&lt;/span&gt;(e.salary) &lt;span style=&quot;color: #8100c2;&quot;&gt;AS&lt;/span&gt; avg_salary
  &lt;span style=&quot;color: #8100c2;&quot;&gt;FROM&lt;/span&gt; departments d
  &lt;span style=&quot;color: #8100c2;&quot;&gt;JOIN&lt;/span&gt; employees e &lt;span style=&quot;color: #8100c2;&quot;&gt;ON&lt;/span&gt; e.department_id = d.id
  &lt;span style=&quot;color: #8100c2;&quot;&gt;GROUP BY&lt;/span&gt; d.id, d.name
)
&lt;span style=&quot;color: #8100c2;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;, avg_salary
&lt;span style=&quot;color: #8100c2;&quot;&gt;FROM&lt;/span&gt; (
  &lt;span style=&quot;color: #8100c2;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color: #8100c2;&quot;&gt;name&lt;/span&gt;, avg_salary,
         &lt;span style=&quot;color: #0051c2;&quot;&gt;RANK&lt;/span&gt;() &lt;span style=&quot;color: #8100c2;&quot;&gt;OVER&lt;/span&gt; (&lt;span style=&quot;color: #8100c2;&quot;&gt;ORDER BY&lt;/span&gt; avg_salary &lt;span style=&quot;color: #8100c2;&quot;&gt;DESC&lt;/span&gt;) &lt;span style=&quot;color: #8100c2;&quot;&gt;AS&lt;/span&gt; rnk
&lt;span style=&quot;color: #8100c2;&quot;&gt;FROM&lt;/span&gt; dept_avg
) t
&lt;span style=&quot;color: #8100c2;&quot;&gt;WHERE&lt;/span&gt; rnk = &lt;span style=&quot;color: teal;&quot;&gt;1&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;RANK()&lt;/code&gt; gives tied departments the same rank, so both Engineering and HR get rank 1. Change &lt;code&gt;rnk = 1&lt;/code&gt; to &lt;code&gt;rnk &amp;lt;= 3&lt;/code&gt; to get the top three salary levels.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;ul&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/6917629587640037673/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/find-departments-with-highest-average.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/6917629587640037673'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/6917629587640037673'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/find-departments-with-highest-average.html' title='Find departments with the highest average salary.'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-7707919671990696949</id><published>2026-11-12T19:30:00.000-08:00</published><updated>2026-11-12T19:30:00.174-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Write a query to get the first and last purchase date for each customer.</title><content type='html'>Let&#39;s create Table schema and feed data into table.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;u&gt;&lt;b&gt;Table schema and sample data:-&lt;/b&gt;&lt;/u&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;CREATE TABLE &lt;b&gt;customers &lt;/b&gt;(&lt;/div&gt;&lt;div&gt;&lt;div&gt;&amp;nbsp; id&amp;nbsp; &amp;nbsp;INT PRIMARY KEY,&lt;/div&gt;&lt;div&gt;&amp;nbsp; name VARCHAR(50) NOT NULL&lt;/div&gt;&lt;div&gt;);&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;CREATE TABLE &lt;b&gt;orders &lt;/b&gt;(&lt;/div&gt;&lt;div&gt;&amp;nbsp; order_id&amp;nbsp; &amp;nbsp; INT PRIMARY KEY,&lt;/div&gt;&lt;div&gt;&amp;nbsp; customer_id INT NOT NULL,&lt;/div&gt;&lt;div&gt;&amp;nbsp; order_date&amp;nbsp; DATE NOT NULL,&lt;/div&gt;&lt;div&gt;&amp;nbsp; amount&amp;nbsp; &amp;nbsp; &amp;nbsp; DECIMAL(10,2),&lt;/div&gt;&lt;div&gt;&amp;nbsp; FOREIGN KEY (customer_id) REFERENCES customers(id)&lt;/div&gt;&lt;div&gt;);&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;INSERT INTO customers (id, name) VALUES&lt;/div&gt;&lt;div&gt;(1, &#39;Asha&#39;),&lt;/div&gt;&lt;div&gt;(2, &#39;Ravi&#39;),&lt;/div&gt;&lt;div&gt;(3, &#39;Meera&#39;),&lt;/div&gt;&lt;div&gt;(4, &#39;Kiran&#39;);&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;INSERT INTO orders (order_id, customer_id, order_date, amount) VALUES&lt;/div&gt;&lt;div&gt;(1, 1, &#39;2026-01-10&#39;, 500),&lt;/div&gt;&lt;div&gt;(2, 1, &#39;2026-03-05&#39;, 300),&lt;/div&gt;&lt;div&gt;(3, 1, &#39;2026-09-20&#39;, 450),&lt;/div&gt;&lt;div&gt;(4, 2, &#39;2026-02-14&#39;, 200),&lt;/div&gt;&lt;div&gt;(5, 2, &#39;2026-02-14&#39;, 150),&lt;/div&gt;&lt;div&gt;(6, 3, &#39;2026-06-01&#39;, 800);&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;u&gt;Query:-&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Show&amp;nbsp; customer names, and include customers who never purchased&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;SELECT&lt;/span&gt; c.id,
       c.name,&amp;nbsp;&lt;/div&gt;&lt;div&gt;       &lt;span style=&quot;color: #0051c2;&quot;&gt;MIN&lt;/span&gt;(o.order_date) &lt;span style=&quot;color: #8100c2;&quot;&gt;AS&lt;/span&gt; first_purchase_date,&amp;nbsp;&lt;/div&gt;&lt;div&gt;       &lt;span style=&quot;color: #0051c2;&quot;&gt;MAX&lt;/span&gt;(o.order_date) &lt;span style=&quot;color: #8100c2;&quot;&gt;AS&lt;/span&gt; last_purchase_date&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;FROM&lt;/span&gt; customers c&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;LEFT JOIN&lt;/span&gt; orders o &lt;span style=&quot;color: #8100c2;&quot;&gt;ON&lt;/span&gt; o.customer_id = c.id&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #8100c2;&quot;&gt;GROUP BY&lt;/span&gt; c.id, c.name
&lt;span style=&quot;color: #8100c2;&quot;&gt;ORDER BY&lt;/span&gt; c.id;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/7707919671990696949/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/write-query-to-get-first-and-last.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/7707919671990696949'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/7707919671990696949'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/write-query-to-get-first-and-last.html' title='Write a query to get the first and last purchase date for each customer.'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-3008818756367159296</id><published>2026-11-11T19:30:00.000-08:00</published><updated>2026-11-11T19:30:00.251-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><title type='text'>Which Azure services have you used in your project, and how do they integrate with each other? </title><content type='html'>&lt;h1&gt;A Note First&lt;/h1&gt;
&lt;p&gt;I haven&#39;t worked on a project myself. I&#39;m an AI, so I can&#39;t claim hands-on experience. But if you&#39;re preparing for an interview or documenting an architecture, here is a realistic reference project built from the services we&#39;ve covered, with how each piece integrates. You can adapt it to your real experience, and you should only describe what you&#39;ve actually done.&lt;/p&gt;
&lt;h2&gt;Example: an order-processing platform&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;Users ─► Front Door (WAF) ─► APIM ─► App Service (.NET Web API)
                                          │
              ┌───────────────────────────┼──────────────────────────┐
              ▼                           ▼                          ▼
         Azure SQL                  Redis (cache)             Service Bus (topic)
                                                                     │
                                          ┌──────────────────────────┼──────────────┐
                                          ▼                          ▼              ▼
                                  Function: billing        Function: shipping   Function: notifications
                                          │
                                  Durable Functions (multi-step workflow)

Cross-cutting: Entra ID, Managed Identity, Key Vault, VNet + Private Endpoints,
               Application Insights, GitHub Actions / Azure Pipelines + Bicep
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;How the pieces integrate&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Edge and API layer&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Front Door&lt;/strong&gt; provides global entry, WAF, and TLS, and forwards to APIM.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;APIM&lt;/strong&gt; validates Entra ID JWTs, applies rate limits, and routes to the backend. The backend accepts traffic only from APIM.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;App Service&lt;/strong&gt; hosts the .NET Web API, with deployment slots for zero-downtime releases.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Identity and secrets&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Entra ID&lt;/strong&gt; issues tokens (auth code + PKCE for users, client credentials for services). The API validates the JWT and checks scopes or roles.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Managed identity&lt;/strong&gt; is how the app and functions reach SQL, Key Vault, Service Bus, and Storage, with RBAC roles and no connection strings.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Key Vault&lt;/strong&gt; holds the few remaining secrets, exposed through Key Vault references in app settings.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Data and messaging&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Azure SQL&lt;/strong&gt; is the system of record, accessed through the app&#39;s managed identity.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Redis&lt;/strong&gt; caches hot reads to reduce database load.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Service Bus&lt;/strong&gt; decouples the API from downstream work. The API publishes an &lt;code&gt;OrderPlaced&lt;/code&gt; event to a &lt;strong&gt;topic&lt;/strong&gt;, and each &lt;strong&gt;subscription&lt;/strong&gt; (billing, shipping, notifications) feeds its own consumer. Dead-letter queues, idempotent handlers, and duplicate detection handle failures.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Azure Functions&lt;/strong&gt; consume those subscriptions with Service Bus triggers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Durable Functions&lt;/strong&gt; orchestrate multi-step flows such as reserve inventory, charge payment, and confirm, with compensation on failure.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Networking&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;VNet integration&lt;/strong&gt; on the app and functions, plus &lt;strong&gt;Private Endpoints&lt;/strong&gt; with private DNS for SQL, Key Vault, Service Bus (Premium), and Storage. Public access is disabled on those services.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Observability&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Application Insights&lt;/strong&gt; (workspace-based, via the OpenTelemetry distro) captures requests, dependencies, and logs across all services, correlated by operation ID. Alerts cover failure rate, p95 latency, queue depth, and DLQ count.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Delivery&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;GitHub Actions&lt;/strong&gt; with OIDC login builds, tests, and deploys to a staging slot, runs a smoke test, then swaps to production after approval.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bicep&lt;/strong&gt; defines the infrastructure, and EF migrations run as a controlled pipeline step.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Scale and availability&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Autoscale with a minimum of two instances, zone-redundant compute and data, and an auto-failover group for SQL if cross-region DR is required.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;br /&gt;&lt;/h2&gt;&lt;blockquote&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/3008818756367159296/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/which-azure-services-have-you-used-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/3008818756367159296'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/3008818756367159296'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/which-azure-services-have-you-used-in.html' title='Which Azure services have you used in your project, and how do they integrate with each other? '/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-7403099418407679354</id><published>2026-11-10T19:30:00.000-08:00</published><updated>2026-11-10T19:30:00.121-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><title type='text'>How do you securely connect Azure services using a VNet and Private Endpoint? </title><content type='html'>&lt;h1&gt;Securely Connecting Azure Services with a VNet and Private Endpoints&lt;/h1&gt;
&lt;p&gt;By default, most Azure PaaS services (Storage, SQL, Key Vault, Service Bus) are reachable through &lt;strong&gt;public endpoints&lt;/strong&gt;, protected only by authentication and firewall rules. A &lt;strong&gt;Private Endpoint&lt;/strong&gt; gives the service a &lt;strong&gt;private IP address inside your VNet&lt;/strong&gt;, so traffic stays on the Microsoft backbone and you can turn public access off entirely.&lt;/p&gt;
&lt;h2&gt;The building blocks&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Virtual Network (VNet):&lt;/strong&gt; your private network in Azure, divided into subnets and secured with NSGs, route tables, and optionally Azure Firewall.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Private Endpoint:&lt;/strong&gt; a network interface (NIC) in one of your subnets, mapped to &lt;strong&gt;one specific resource and sub-resource&lt;/strong&gt; (for example, the &lt;em&gt;blob&lt;/em&gt; service of one storage account). It is powered by &lt;strong&gt;Azure Private Link&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Private DNS zone:&lt;/strong&gt; makes the service&#39;s normal hostname (&lt;code&gt;mystorage.blob.core.windows.net&lt;/code&gt;) resolve to the private IP from inside your network. &lt;strong&gt;DNS is the most common cause of Private Endpoint problems.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;VNet integration:&lt;/strong&gt; lets an App Service or Function App make &lt;strong&gt;outbound&lt;/strong&gt; calls into your VNet.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Inbound vs. outbound (a frequent point of confusion)&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Need&lt;/th&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Reach a PaaS service privately (SQL, Storage, Key Vault)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Private Endpoint&lt;/strong&gt; on that service&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Let App Service/Functions call into the VNet&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Regional VNet integration&lt;/strong&gt; (outbound only)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Make the web app or function itself privately reachable&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Private Endpoint on the app&lt;/strong&gt; (inbound)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;An app typically needs both: VNet integration so its outbound traffic enters the VNet, and private endpoints on the services it calls.&lt;/p&gt;
&lt;h2&gt;How the traffic flows&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;App Service (VNet integration, snet-app)
        │  1. DNS: mystorage.blob.core.windows.net
        │     → CNAME privatelink.blob... → Private DNS zone → 10.0.2.4
        ▼
VNet ──► Private Endpoint NIC (10.0.2.4, snet-pe) ──► Storage account (public access disabled)
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Step-by-step setup&lt;/h2&gt;
&lt;h3&gt;1. Create the VNet and subnets&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az network vnet create -g my-rg -n my-vnet --address-prefixes 10.0.0.0/16

# Subnet for app outbound traffic (delegated to App Service)
az network vnet subnet create -g my-rg --vnet-name my-vnet -n snet-app \
  --address-prefixes 10.0.1.0/24 --delegations Microsoft.Web/serverFarms

# Subnet for private endpoints
az network vnet subnet create -g my-rg --vnet-name my-vnet -n snet-pe \
  --address-prefixes 10.0.2.0/24
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Use a &lt;strong&gt;separate subnet for private endpoints&lt;/strong&gt;, and size subnets for growth. A delegated integration subnet can&#39;t be shared with other resource types.&lt;/p&gt;
&lt;h3&gt;2. Create the Private Endpoint&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az network private-endpoint create -g my-rg -n pe-storage-blob \
  --vnet-name my-vnet --subnet snet-pe \
  --private-connection-resource-id $(az storage account show -n mystorage -g my-rg --query id -o tsv) \
  --group-id blob --connection-name storage-blob-conn
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;--group-id&lt;/code&gt; selects the sub-resource. Storage has separate ones for &lt;code&gt;blob&lt;/code&gt;, &lt;code&gt;queue&lt;/code&gt;, &lt;code&gt;table&lt;/code&gt;, &lt;code&gt;file&lt;/code&gt;, and &lt;code&gt;dfs&lt;/code&gt;, and each needs its own endpoint.&lt;/p&gt;
&lt;h3&gt;3. Set up private DNS&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az network private-dns zone create -g my-rg -n privatelink.blob.core.windows.net

az network private-dns link vnet create -g my-rg \
  -n link-my-vnet -z privatelink.blob.core.windows.net \
  -v my-vnet -e false

# Automatically creates/maintains the A record for the endpoint
az network private-endpoint dns-zone-group create -g my-rg \
  --endpoint-name pe-storage-blob -n default \
  --private-dns-zone privatelink.blob.core.windows.net --zone-name blob
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;4. Close the public door&lt;/h3&gt;
&lt;p&gt;Creating the endpoint doesn&#39;t remove the public one. Disable it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az storage account update -n mystorage -g my-rg --public-network-access Disabled
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Most services have an equivalent setting (&lt;code&gt;publicNetworkAccess&lt;/code&gt;, &quot;Deny public network access&quot;, or firewall set to deny).&lt;/p&gt;
&lt;h3&gt;5. Connect the app&#39;s outbound traffic to the VNet&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az webapp vnet-integration add -g my-rg -n my-app --vnet my-vnet --subnet snet-app
az webapp config set -g my-rg -n my-app --vnet-route-all-enabled true
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Routing all outbound traffic through the VNet ensures private DNS and your NSG/firewall rules apply to everything the app calls. Without it, only private (RFC1918) destinations go through the VNet.&lt;/p&gt;
&lt;h2&gt;Common services: sub-resource and DNS zone&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Service&lt;/th&gt;
&lt;th&gt;Group ID&lt;/th&gt;
&lt;th&gt;Private DNS zone&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Storage (Blob)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;blob&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;privatelink.blob.core.windows.net&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Azure SQL&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sqlServer&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;privatelink.database.windows.net&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Key Vault&lt;/td&gt;
&lt;td&gt;&lt;code&gt;vault&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;privatelink.vaultcore.azure.net&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Service Bus / Event Hubs&lt;/td&gt;
&lt;td&gt;&lt;code&gt;namespace&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;privatelink.servicebus.windows.net&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cosmos DB (NoSQL)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Sql&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;privatelink.documents.azure.com&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;App Service / Functions&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sites&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;privatelink.azurewebsites.net&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Container Registry&lt;/td&gt;
&lt;td&gt;&lt;code&gt;registry&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;privatelink.azurecr.io&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Redis&lt;/td&gt;
&lt;td&gt;&lt;code&gt;redisCache&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;privatelink.redis.cache.windows.net&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Zone names are standardized, and the current list is in the Azure docs (&quot;Private endpoint DNS zone values&quot;). Using the exact name matters, because the service&#39;s CNAME points to it.&lt;/p&gt;
&lt;h2&gt;Layers of network security&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Private Endpoints&lt;/strong&gt; for inbound access to PaaS, with &lt;strong&gt;public access disabled&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NSGs&lt;/strong&gt; on subnets. By default, NSGs and UDRs don&#39;t apply to private endpoint traffic. Enable the subnet&#39;s &lt;code&gt;privateEndpointNetworkPolicies&lt;/code&gt; setting if you want to enforce them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Azure Firewall or an NVA&lt;/strong&gt; for egress control: allow only the destinations and FQDNs the app needs, and block general internet access to reduce data exfiltration risk.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Identity on top of the network:&lt;/strong&gt; keep using &lt;strong&gt;managed identity and RBAC&lt;/strong&gt;. Network isolation doesn&#39;t replace authentication, and a private endpoint without proper RBAC is still over-trusting.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Private Link per resource&lt;/strong&gt;, not per service: a private endpoint is tied to &lt;em&gt;your specific&lt;/em&gt; storage account, so it can&#39;t be used to reach another tenant&#39;s account. This is a key exfiltration protection that service endpoints lack.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Private Endpoint vs. Service Endpoint&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Service Endpoint&lt;/th&gt;
&lt;th&gt;Private Endpoint&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Target IP&lt;/td&gt;
&lt;td&gt;Still the service&#39;s public IP (traffic routed over backbone)&lt;/td&gt;
&lt;td&gt;Private IP in your VNet&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scope&lt;/td&gt;
&lt;td&gt;Entire service type in a region&lt;/td&gt;
&lt;td&gt;One specific resource&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reachable from on-premises&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes (via VPN/ExpressRoute)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Exfiltration protection&lt;/td&gt;
&lt;td&gt;Limited&lt;/td&gt;
&lt;td&gt;Strong&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DNS changes&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;Required (private DNS)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cost&lt;/td&gt;
&lt;td&gt;Free&lt;/td&gt;
&lt;td&gt;Hourly charge plus data processed&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Service endpoints are simpler and free, but Private Endpoints are the recommended choice for stronger isolation and hybrid access.&lt;/p&gt;
&lt;h2&gt;Multi-VNet and hybrid networks&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Hub-and-spoke:&lt;/strong&gt; put shared services, firewall, and DNS in a hub VNet and peer spokes to it. Private DNS zones are typically &lt;strong&gt;linked to the hub (and spokes)&lt;/strong&gt;, or centralized.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;On-premises access:&lt;/strong&gt; connect via VPN Gateway or ExpressRoute. On-premises DNS must &lt;strong&gt;forward&lt;/strong&gt; the &lt;code&gt;privatelink&lt;/code&gt; queries to Azure, typically through &lt;strong&gt;Azure DNS Private Resolver&lt;/strong&gt; (or a DNS forwarder VM) in the VNet. Forward the &lt;em&gt;public&lt;/em&gt; zone name (e.g., &lt;code&gt;blob.core.windows.net&lt;/code&gt;) to Azure DNS, not the &lt;code&gt;privatelink&lt;/code&gt; zone directly.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;VNet peering&lt;/strong&gt; doesn&#39;t automatically share DNS. Each VNet that needs to resolve the private records must be linked to the private DNS zone or use a shared resolver.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;Azure Policy&lt;/strong&gt; to enforce private endpoints and deny public access across subscriptions, and to auto-create DNS zone groups.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Service-specific gotchas&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Azure Functions:&lt;/strong&gt; the function&#39;s host &lt;strong&gt;storage account&lt;/strong&gt; needs private endpoints for blob, queue, table, and file (the file share is used on some plans), and you may need extra settings for content share routing. Check the current Functions networking docs for your plan.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Service Bus:&lt;/strong&gt; private endpoints require the &lt;strong&gt;Premium&lt;/strong&gt; tier.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Container Registry:&lt;/strong&gt; Private Link requires the &lt;strong&gt;Premium&lt;/strong&gt; tier.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Key Vault:&lt;/strong&gt; with public access disabled, only callers with a private path can reach it, including your pipelines. Make sure CI/CD agents run in the VNet (self-hosted agents or private agents) or use a deliberate exception.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Azure SQL:&lt;/strong&gt; private endpoints work with the &lt;strong&gt;Proxy/Redirect&lt;/strong&gt; connection policy. Redirect needs additional ports reachable inside the VNet, so check your NSG rules.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Application Insights / Azure Monitor:&lt;/strong&gt; use an &lt;strong&gt;Azure Monitor Private Link Scope (AMPLS)&lt;/strong&gt; to keep telemetry traffic private.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cross-subscription or cross-tenant endpoints:&lt;/strong&gt; the connection may need to be &lt;strong&gt;approved&lt;/strong&gt; on the target resource (manual approval flow).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Deployment access:&lt;/strong&gt; if you disable public access on an app&#39;s SCM site or a storage account, make sure your deployment path (private agents, VNet-based runners) can still reach it.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Troubleshooting checklist&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;DNS first:&lt;/strong&gt; from inside the VNet (Kudu console, a VM, or a container), run &lt;code&gt;nslookup mystorage.blob.core.windows.net&lt;/code&gt;. It must return the &lt;strong&gt;private IP&lt;/strong&gt; (10.0.2.x). A public IP means the DNS zone link, zone group, or custom DNS forwarding is wrong.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Check the endpoint state:&lt;/strong&gt; the private endpoint connection should be &lt;code&gt;Approved&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Check the VNet&#39;s DNS servers:&lt;/strong&gt; if you use custom DNS, it must forward to Azure DNS (&lt;code&gt;168.63.129.16&lt;/code&gt;) or a Private Resolver.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test connectivity:&lt;/strong&gt; &lt;code&gt;tcpping&lt;/code&gt; (App Service Windows), &lt;code&gt;curl&lt;/code&gt;, or &lt;strong&gt;Network Watcher → Connection troubleshoot&lt;/strong&gt; and &lt;strong&gt;IP flow verify&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Review NSG, UDR, and firewall rules,&lt;/strong&gt; especially if network policies for private endpoints are enabled.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Verify the app is actually routing through the VNet:&lt;/strong&gt; the integration subnet, route-all setting, and that the integration is connected.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Confirm the public path is intentionally blocked&lt;/strong&gt; (a &lt;code&gt;403&lt;/code&gt; from the service often means the request arrived over the public path, not the private one).&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Good practices&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Define everything as code&lt;/strong&gt; (Bicep or Terraform), including endpoints, DNS zones, and links, so environments match.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Centralize private DNS zones&lt;/strong&gt; (hub) and automate record creation with DNS zone groups or Azure Policy.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Plan IP address space&lt;/strong&gt; early. Overlapping ranges block peering and hybrid connectivity later.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Disable public network access&lt;/strong&gt; on every service that has a private endpoint, unless you have a documented exception.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Combine&lt;/strong&gt; private networking with managed identity, RBAC, Key Vault, and diagnostic logging to Log Analytics.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mind the cost:&lt;/strong&gt; each endpoint has an hourly charge plus per-GB processing, and you need one per sub-resource. Consolidate where reasonable (for example, shared services in the hub).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Minimal secure pattern&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Create a VNet with &lt;strong&gt;separate subnets&lt;/strong&gt; for app integration and private endpoints.&lt;/li&gt;
&lt;li&gt;Add &lt;strong&gt;VNet integration&lt;/strong&gt; (with route-all) to the App Service or Function App.&lt;/li&gt;
&lt;li&gt;Create &lt;strong&gt;Private Endpoints&lt;/strong&gt; for Storage, SQL, Key Vault, and Service Bus, each with the &lt;strong&gt;correct private DNS zone&lt;/strong&gt; linked to the VNet.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Disable public network access&lt;/strong&gt; on those services.&lt;/li&gt;
&lt;li&gt;Authenticate with &lt;strong&gt;managed identity and RBAC&lt;/strong&gt;, and put Front Door or Application Gateway (WAF) in front of the app for inbound traffic.&lt;/li&gt;
&lt;li&gt;Verify DNS resolves to private IPs, and monitor with Network Watcher and diagnostic logs.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/7403099418407679354/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/how-do-you-securely-connect-azure.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/7403099418407679354'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/7403099418407679354'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/how-do-you-securely-connect-azure.html' title='How do you securely connect Azure services using a VNet and Private Endpoint? '/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-2862862012707285511</id><published>2026-11-09T19:30:00.000-08:00</published><updated>2026-11-09T19:30:00.118-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><title type='text'>What is AKS, and when would you choose it over App Service?</title><content type='html'>&lt;h1&gt;Azure Kubernetes Service (AKS)&lt;/h1&gt;
&lt;p&gt;AKS is Azure&#39;s managed Kubernetes service. Azure runs the &lt;strong&gt;control plane&lt;/strong&gt; (API server, scheduler, etcd) for you, and you run the &lt;strong&gt;workloads&lt;/strong&gt;: you package your app as containers, describe the desired state in Kubernetes manifests, and Kubernetes keeps it running, scaled, and healthy across a pool of VMs called &lt;strong&gt;nodes&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;What you get and what you still own&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Azure manages&lt;/th&gt;
&lt;th&gt;You manage&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Control plane (HA, patching, upgrades on request)&lt;/td&gt;
&lt;td&gt;Node pools: sizes, zones, upgrade cadence&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Integration with Entra ID, ACR, Azure Monitor, Key Vault&lt;/td&gt;
&lt;td&gt;Deployments, Services, Ingress, autoscaling configuration&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Optional node image patching and auto-upgrade channels&lt;/td&gt;
&lt;td&gt;Network design, policies, and security hardening&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Observability, cost control, and application-level resilience&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;AKS Automatic&lt;/strong&gt; is a newer mode that takes over more of this (node provisioning, scaling, networking defaults, and security baselines), which reduces the operational burden. &lt;strong&gt;Standard&lt;/strong&gt; mode gives full control but more responsibility. Check the current docs for what each mode includes.&lt;/p&gt;
&lt;h2&gt;Core concepts&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Cluster:&lt;/strong&gt; control plane plus one or more node pools.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Node pool:&lt;/strong&gt; a group of identical VMs (system pools for cluster components, user pools for your apps). You can mix sizes, GPU nodes, spot nodes, and Linux/Windows.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pod:&lt;/strong&gt; the smallest deployable unit, one or more containers sharing a network namespace.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Deployment:&lt;/strong&gt; declares the desired number of pod replicas and handles rolling updates.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Service and Ingress:&lt;/strong&gt; stable internal addressing and HTTP routing into the cluster.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HPA / KEDA / cluster autoscaler:&lt;/strong&gt; scale pods on metrics or events, and nodes to fit the pods.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Namespaces, RBAC, network policies:&lt;/strong&gt; isolation and access control between teams and workloads.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Workload identity:&lt;/strong&gt; lets pods authenticate to Azure services via Entra ID with no stored secrets (the Kubernetes counterpart of managed identity).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;When to choose AKS over App Service&lt;/h2&gt;
&lt;p&gt;Choose &lt;strong&gt;AKS&lt;/strong&gt; when you have a concrete need that App Service can&#39;t meet well:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Many services, one platform.&lt;/strong&gt; Dozens of microservices with different scaling and release needs, where Kubernetes&#39; scheduling and bin-packing are efficient and consistent.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Kubernetes-native tooling is a requirement.&lt;/strong&gt; Helm, operators, custom resource definitions, Argo CD/Flux GitOps, Istio or other service meshes, admission controllers like OPA/Gatekeeper or Kyverno.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Complex deployment topologies.&lt;/strong&gt; Sidecars, init containers, daemonsets, stateful sets, multi-container pods, and canary or blue/green rollouts with traffic splitting at the mesh or ingress layer.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fine-grained control&lt;/strong&gt; over scheduling, node types (GPU, high-memory, spot), pod placement, resource limits, and network policy.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Portability.&lt;/strong&gt; You want the same deployment model across Azure, other clouds, and on-premises (with Azure Arc or other distributions), and want to limit platform lock-in.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Specialized workloads.&lt;/strong&gt; ML training and inference, batch/HPC jobs, event-driven processing with KEDA, or software that ships as a Helm chart or operator (databases, message brokers, observability stacks).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;You have the skills.&lt;/strong&gt; A platform or DevOps team that already knows Kubernetes and can own cluster operations.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Choose &lt;strong&gt;App Service&lt;/strong&gt; when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You have &lt;strong&gt;one or a few APIs or web apps&lt;/strong&gt; and want to ship fast.&lt;/li&gt;
&lt;li&gt;The team is &lt;strong&gt;small or doesn&#39;t have Kubernetes expertise&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Deployment slots, built-in TLS, Easy Auth, and managed scaling&lt;/strong&gt; cover your needs.&lt;/li&gt;
&lt;li&gt;You want &lt;strong&gt;low operational overhead&lt;/strong&gt; and a predictable, per-plan cost.&lt;/li&gt;
&lt;li&gt;You don&#39;t need anything beyond &quot;run this app, scale it, keep it healthy.&quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Side-by-side&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;App Service&lt;/th&gt;
&lt;th&gt;AKS&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Abstraction&lt;/td&gt;
&lt;td&gt;Deploy an app&lt;/td&gt;
&lt;td&gt;Run a cluster&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ops burden&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;Moderate to high (lower with Automatic)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Skills needed&lt;/td&gt;
&lt;td&gt;Azure and your framework&lt;/td&gt;
&lt;td&gt;Kubernetes, containers, networking&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Packaging&lt;/td&gt;
&lt;td&gt;Code or container&lt;/td&gt;
&lt;td&gt;Containers only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time to first deploy&lt;/td&gt;
&lt;td&gt;Minutes&lt;/td&gt;
&lt;td&gt;Hours to days (cluster, ingress, identity, CI/CD)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Zero-downtime releases&lt;/td&gt;
&lt;td&gt;Slots and swap&lt;/td&gt;
&lt;td&gt;Rolling updates, canary via ingress or mesh&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ecosystem&lt;/td&gt;
&lt;td&gt;Azure-native&lt;/td&gt;
&lt;td&gt;Entire Kubernetes ecosystem&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cost shape&lt;/td&gt;
&lt;td&gt;Per plan&lt;/td&gt;
&lt;td&gt;Per node (paid when idle) plus platform effort&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Typical APIs and web apps&lt;/td&gt;
&lt;td&gt;Large, complex, or Kubernetes-standardized platforms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;The trade-offs to be honest about&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;AKS is a platform, not an app host.&lt;/strong&gt; Ingress, certificates, secrets, observability, policy, upgrades, and cost management are all things you assemble and maintain.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cluster upgrades are real work.&lt;/strong&gt; Kubernetes releases frequently, and versions go out of support. You need an upgrade process and test environment.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Idle capacity costs money.&lt;/strong&gt; Nodes run whether or not they&#39;re busy, so you need good bin-packing and autoscaling to be cost-effective.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Security is shared.&lt;/strong&gt; Pod security, network policies, image scanning, RBAC, and supply-chain controls are your responsibility.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Complexity can outweigh benefits&lt;/strong&gt; for a single API. Many teams adopt AKS for flexibility they never use.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;The middle ground&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Azure Container Apps&lt;/strong&gt; runs containers on Kubernetes under the hood, with KEDA scaling, revisions with traffic splitting, Dapr, and scale to zero, but without exposing the cluster. If your reason for considering AKS is &quot;I have containers and want autoscaling and microservices,&quot; Container Apps often fits without the operational cost. Move to AKS when you hit its limits (need for custom operators, daemonsets, node-level control, or specific networking).&lt;/p&gt;
&lt;h2&gt;A minimal AKS deployment&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az aks create --name my-aks --resource-group my-rg \
  --node-count 3 --zones 1 2 3 \
  --enable-managed-identity --enable-oidc-issuer --enable-workload-identity \
  --attach-acr myacr --network-plugin azure --network-plugin-mode overlay

az aks get-credentials --name my-aks --resource-group my-rg
kubectl apply -f deployment.yaml
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A production setup also typically includes an ingress controller (NGINX or Application Gateway for Containers), cert-management, Azure Monitor/Container Insights, Key Vault secrets via the CSI driver, network policies, pod disruption budgets, autoscaling, and a GitOps or CI/CD pipeline.&lt;/p&gt;
&lt;h2&gt;Decision rule&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;One to a handful of APIs, small team&lt;/strong&gt; → &lt;strong&gt;App Service&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Containers, microservices, but you want minimal ops&lt;/strong&gt; → &lt;strong&gt;Container Apps&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Many services, platform team, Kubernetes ecosystem or portability needs, custom scheduling or workloads&lt;/strong&gt; → &lt;strong&gt;AKS&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Start with the simplest platform that meets today&#39;s requirements. Because App Service, Container Apps, and AKS can all run the same container image, containerizing your app keeps the door open to move later when you have a concrete reason.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/2862862012707285511/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/what-is-aks-and-when-would-you-choose.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/2862862012707285511'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/2862862012707285511'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/what-is-aks-and-when-would-you-choose.html' title='What is AKS, and when would you choose it over App Service?'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-1196848860557830408</id><published>2026-11-08T19:30:00.000-08:00</published><updated>2026-11-08T19:30:00.165-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><title type='text'>How do you achieve scalability and high availability for applications in Azure?</title><content type='html'>&lt;h1&gt;Scalability and High Availability in Azure&lt;/h1&gt;
&lt;p&gt;These are related but different goals:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Scalability&lt;/strong&gt; is the ability to handle more (or less) load by adding or removing capacity.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;High availability (HA)&lt;/strong&gt; is the ability to keep serving requests when components, zones, or regions fail.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Disaster recovery (DR)&lt;/strong&gt; is the ability to recover after a major outage. It is defined by &lt;strong&gt;RTO&lt;/strong&gt; (how long you can be down) and &lt;strong&gt;RPO&lt;/strong&gt; (how much data you can lose).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Both are mostly design decisions, not features you switch on. The platform provides the building blocks, but your application has to be built to use them.&lt;/p&gt;
&lt;h2&gt;Part 1: Scalability&lt;/h2&gt;
&lt;h3&gt;Scale up vs. scale out&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Scale up (vertical):&lt;/strong&gt; a bigger SKU (more CPU/RAM). It&#39;s simple but has a ceiling and often causes downtime or restarts.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scale out (horizontal):&lt;/strong&gt; more instances behind a load balancer. This is the preferred approach for web tiers and APIs because it scales almost without limit and also helps availability.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Design the app to scale out&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Be stateless.&lt;/strong&gt; Don&#39;t keep session or user state in instance memory. Use a distributed cache (Azure Cache for Redis), a database, or signed tokens (JWTs).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Don&#39;t depend on local disk&lt;/strong&gt; for anything that must persist.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Make startup fast&lt;/strong&gt; so new instances can serve traffic quickly.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use asynchronous processing.&lt;/strong&gt; Put slow work behind a queue (Service Bus, Storage Queues) and process it with background workers. This smooths spikes (load leveling) and lets each tier scale independently.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cache aggressively:&lt;/strong&gt; Redis for hot data, a CDN or Front Door for static and cacheable content, and output or response caching where it&#39;s safe.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Avoid chatty and blocking calls.&lt;/strong&gt; Use async I/O, batch where possible, and reuse connections (&lt;code&gt;IHttpClientFactory&lt;/code&gt;, connection pooling).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Autoscale by compute type&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Service&lt;/th&gt;
&lt;th&gt;How it scales&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;App Service&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Autoscale rules (CPU, memory, requests, queue length, schedule) or automatic scaling on supported tiers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Azure Functions&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Event-driven and automatic on Consumption, Flex Consumption, and Premium; Premium keeps pre-warmed instances&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Container Apps&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;KEDA-based scaling on HTTP concurrency, queue depth, and so on, including scale to zero&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;AKS&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Horizontal Pod Autoscaler or KEDA for pods, plus the cluster autoscaler (or node auto-provisioning) for nodes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;VMs&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Virtual Machine Scale Sets with autoscale rules&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Example for App Service:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az monitor autoscale create --resource-group my-rg \
  --resource my-plan --resource-type Microsoft.Web/serverfarms \
  --name my-autoscale --min-count 2 --max-count 10 --count 2

az monitor autoscale rule create --resource-group my-rg --autoscale-name my-autoscale \
  --condition &quot;CpuPercentage &amp;gt; 70 avg 5m&quot; --scale out 2

az monitor autoscale rule create --resource-group my-rg --autoscale-name my-autoscale \
  --condition &quot;CpuPercentage &amp;lt; 30 avg 10m&quot; --scale in 1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Tips: keep a &lt;strong&gt;minimum of two instances&lt;/strong&gt;, scale out faster than you scale in, leave a gap between the scale-out and scale-in thresholds to avoid flapping, and scale on the metric that actually reflects your bottleneck (queue length is often better than CPU).&lt;/p&gt;
&lt;h3&gt;Scale the data tier (usually the real bottleneck)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Azure SQL:&lt;/strong&gt; scale vCores or DTUs, use &lt;strong&gt;Hyperscale&lt;/strong&gt; for very large databases, offload reads to &lt;strong&gt;read replicas&lt;/strong&gt; (read scale-out), and fix query and index problems before buying more capacity.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cosmos DB:&lt;/strong&gt; choose a good &lt;strong&gt;partition key&lt;/strong&gt; (the most important decision), use &lt;strong&gt;autoscale throughput&lt;/strong&gt;, and watch for hot partitions and 429s.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Storage:&lt;/strong&gt; scales very high, but spread load across blob prefixes and watch throttling limits.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Redis:&lt;/strong&gt; pick the right tier and use clustering for larger datasets.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Messaging:&lt;/strong&gt; Service Bus Premium and Event Hubs scale with messaging units or throughput units, and Event Hubs scales with partitions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Partition and shard&lt;/strong&gt; data (by tenant, region, or key) when one database can&#39;t handle the write load.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CQRS and read models&lt;/strong&gt; let you scale reads separately from writes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Test it&lt;/h3&gt;
&lt;p&gt;Use &lt;strong&gt;Azure Load Testing&lt;/strong&gt; (JMeter-based) to find your limits before users do, and validate that autoscale triggers when you expect.&lt;/p&gt;
&lt;h2&gt;Part 2: High Availability&lt;/h2&gt;
&lt;h3&gt;Layered redundancy&lt;/h3&gt;
&lt;p&gt;Azure offers redundancy at three levels:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Within a datacenter:&lt;/strong&gt; multiple instances, fault domains, and update domains.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Across availability zones:&lt;/strong&gt; physically separate datacenters in one region, with independent power, cooling, and networking. This protects against a datacenter failure.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Across regions:&lt;/strong&gt; protects against a regional outage. This is the most expensive option and is only needed for stricter requirements.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Start with zone redundancy.&lt;/strong&gt; For most workloads it gives a strong availability improvement at modest cost and complexity.&lt;/p&gt;
&lt;h3&gt;Zone redundancy by service&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Service&lt;/th&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;App Service&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Zone-redundant plan (supported on Premium v3 and similar tiers; requires multiple instances)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Functions&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Zone redundancy on Premium and Flex Consumption (check current regional support)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;AKS&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Spread node pools across zones; use pod topology spread constraints and pod disruption budgets&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Azure SQL&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Zone-redundant configuration (General Purpose and Business Critical)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cosmos DB&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Zone redundancy per region, multi-region replication, and optional multi-region writes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Storage&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;ZRS&lt;/strong&gt; or &lt;strong&gt;GZRS&lt;/strong&gt; (zone plus geo-redundant)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Service Bus / Event Hubs&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Zone redundancy on Premium (and Standard in supported regions)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Redis&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Zone-redundant tiers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Load balancing&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Zone-redundant Standard Load Balancer, Application Gateway v2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;VMs&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Spread across zones using VM Scale Sets or availability zone placement&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Zone and region support varies by region and SKU, so check the current documentation for yours.&lt;/p&gt;
&lt;h3&gt;Multi-region architectures&lt;/h3&gt;
&lt;p&gt;Pick a model based on your RTO/RPO and budget:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Strategy&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;RTO&lt;/th&gt;
&lt;th&gt;Cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Backup and restore&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Restore from backups in another region&lt;/td&gt;
&lt;td&gt;Hours to days&lt;/td&gt;
&lt;td&gt;Lowest&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Pilot light&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Minimal core (data replication, infrastructure defined as code) kept ready; scale up on failover&lt;/td&gt;
&lt;td&gt;Tens of minutes to hours&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Warm standby&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Scaled-down but running copy; scale up on failover&lt;/td&gt;
&lt;td&gt;Minutes&lt;/td&gt;
&lt;td&gt;Medium&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Active-active&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Both regions serve traffic&lt;/td&gt;
&lt;td&gt;Near zero&lt;/td&gt;
&lt;td&gt;Highest&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Components:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Azure Front Door:&lt;/strong&gt; global, Layer 7 load balancing with health probes, failover, WAF, and caching. It&#39;s the usual choice for HTTP APIs and web apps.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Traffic Manager:&lt;/strong&gt; DNS-based routing and failover for non-HTTP or simpler needs (DNS caching makes failover slower).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data replication:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Azure SQL:&lt;/strong&gt; &lt;strong&gt;auto-failover groups&lt;/strong&gt; give a stable listener endpoint and managed cross-region failover.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cosmos DB:&lt;/strong&gt; built-in multi-region replication, automatic failover, and an option for multi-region writes with conflict resolution.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Storage:&lt;/strong&gt; GRS, GZRS, or RA-GRS for a read-only secondary.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Service Bus:&lt;/strong&gt; Geo-Replication or Geo-Disaster Recovery on Premium. Note that disaster recovery replicates metadata, and (depending on feature) not necessarily all in-flight messages, so check the semantics.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Azure Site Recovery&lt;/strong&gt; replicates VMs, and &lt;strong&gt;Azure Backup&lt;/strong&gt; protects data against deletion and corruption. Replication is not a backup, because corruption replicates too.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Infrastructure as code&lt;/strong&gt; (Bicep or Terraform) so you can rebuild or scale a region quickly and consistently.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Do the SLA math&lt;/h3&gt;
&lt;p&gt;Availability multiplies across dependencies in a serial chain. If your API (99.95%) depends on a database (99.99%) and a cache (99.9%), the composite is roughly 0.9995 × 0.9999 × 0.999 ≈ &lt;strong&gt;99.84%&lt;/strong&gt;, which is lower than any single component. Redundancy (zones, regions) raises the figure, and removing unnecessary hard dependencies helps as well. Use the Azure SLA documentation and the &lt;strong&gt;composite SLA&lt;/strong&gt; approach to estimate it, and remember the SLA is a financial commitment from Microsoft, not a guarantee of actual uptime.&lt;/p&gt;
&lt;h2&gt;Part 3: Resilient application design&lt;/h2&gt;
&lt;p&gt;Infrastructure redundancy doesn&#39;t help if the app falls over on the first transient fault.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Retries with exponential backoff and jitter&lt;/strong&gt; for transient errors (Polly or &lt;code&gt;Microsoft.Extensions.Http.Resilience&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Timeouts&lt;/strong&gt; on every outbound call. The default is often far too long.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Circuit breakers&lt;/strong&gt; to stop hammering a failing dependency.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bulkheads&lt;/strong&gt; to isolate resource pools, so one slow dependency doesn&#39;t consume all threads or connections.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rate limiting and throttling&lt;/strong&gt; to protect yourself from overload (APIM, Front Door, app-level).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Graceful degradation:&lt;/strong&gt; serve cached or reduced functionality when a non-critical dependency fails.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Idempotent operations&lt;/strong&gt;, so retries and redeliveries are safe.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Health probes&lt;/strong&gt; (&lt;code&gt;/health/live&lt;/code&gt; and &lt;code&gt;/health/ready&lt;/code&gt;), so load balancers and orchestrators remove unhealthy instances.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Queue-based decoupling&lt;/strong&gt;, so a downstream outage becomes a backlog and not an error for users.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Avoid single points of failure&lt;/strong&gt; (a single instance, a single database, a single region-bound dependency).&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddHttpClient(&quot;orders&quot;)
    .AddStandardResilienceHandler();   // retry, circuit breaker, timeouts, rate limiter
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Part 4: Operations and verification&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Monitor&lt;/strong&gt; with Application Insights and Azure Monitor. Alert on error rate, latency, saturation, queue depth, and dependency health.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Define SLOs&lt;/strong&gt; (for example, 99.9% of requests succeed under 500 ms) and track error budgets.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Safe deployments:&lt;/strong&gt; deployment slots, canary or blue/green releases, and automatic rollback, so your own changes don&#39;t cause the outages.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test failure&lt;/strong&gt; with &lt;strong&gt;Azure Chaos Studio&lt;/strong&gt; (inject zone failures, latency, and dependency faults) and run &lt;strong&gt;failover drills&lt;/strong&gt;. An untested DR plan is a hope, not a plan.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Document runbooks&lt;/strong&gt; for failover and failback, including who decides and how data conflicts are resolved.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Review against the Azure Well-Architected Framework&lt;/strong&gt; (Reliability and Performance Efficiency pillars) and use &lt;strong&gt;Azure Advisor&lt;/strong&gt; for recommendations.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Example: a typical highly available, scalable API&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;Users ─► Front Door (WAF, global LB, health probes)
              │
              ├─► Region A (zone-redundant)               ├─► Region B (warm standby / active)
              │    App Service or Container Apps          │    same stack, scaled down or equal
              │    (autoscale, min 2+ instances)          │
              │    ├─ Redis (zone-redundant)              │
              │    ├─ Service Bus Premium (zone-redundant)│
              │    └─ Azure SQL (zone-redundant)  ──── auto-failover group ────► Azure SQL (secondary)
              │
              └─► Application Insights + alerts, Key Vault, managed identities
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Practical roadmap&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Make the app stateless&lt;/strong&gt; and add health checks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Run at least two instances&lt;/strong&gt; with autoscale on a metric that matches your bottleneck.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Enable zone redundancy&lt;/strong&gt; for compute, database, cache, storage, and messaging.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Add resilience patterns&lt;/strong&gt; (timeouts, retries with backoff, circuit breakers) and decouple slow work with queues.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Define RTO/RPO&lt;/strong&gt;, then choose backup-restore, warm standby, or active-active accordingly.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Add Front Door&lt;/strong&gt; and a second region only if your requirements justify the cost and complexity.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Load test, run chaos and failover drills&lt;/strong&gt;, and set alerts and SLOs.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;A caution: multi-region active-active is often over-built. Many workloads meet their business needs with &lt;strong&gt;zone redundancy, good backups, and a tested restore or warm-standby plan&lt;/strong&gt;, at a fraction of the cost and complexity.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/1196848860557830408/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/how-do-you-achieve-scalability-and-high.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/1196848860557830408'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/1196848860557830408'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/how-do-you-achieve-scalability-and-high.html' title='How do you achieve scalability and high availability for applications in Azure?'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-8229926690365947742</id><published>2026-11-07T19:30:00.000-08:00</published><updated>2026-11-07T19:30:00.169-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><title type='text'>How do you handle retries, failures, duplicate messages, and dead-letter queues in Service Bus?</title><content type='html'>&lt;h1&gt;Retries, Failures, Duplicates, and Dead-Lettering in Service Bus&lt;/h1&gt;
&lt;p&gt;Service Bus gives you &lt;strong&gt;at-least-once delivery&lt;/strong&gt;, so your design has to assume that messages can fail, be retried, and arrive more than once. Four mechanisms work together:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Client retries&lt;/strong&gt; for transient errors when talking to Service Bus&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Message redelivery&lt;/strong&gt; (peek-lock and delivery count) when processing fails&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dead-lettering&lt;/strong&gt; for messages that can&#39;t be processed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Duplicate handling&lt;/strong&gt;, through broker-side detection and idempotent consumers&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;1. Two kinds of retry&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Client-side retries&lt;/strong&gt; cover transient failures when sending or receiving (network blips, throttling, server busy). The Azure SDK retries automatically, and you can tune it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var client = new ServiceBusClient(
    &quot;mynamespace.servicebus.windows.net&quot;,
    new DefaultAzureCredential(),
    new ServiceBusClientOptions
    {
        RetryOptions = new ServiceBusRetryOptions
        {
            Mode = ServiceBusRetryMode.Exponential,
            MaxRetries = 5,
            Delay = TimeSpan.FromSeconds(1),
            MaxDelay = TimeSpan.FromSeconds(30)
        }
    });
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Message redelivery&lt;/strong&gt; covers failures in &lt;em&gt;your processing logic&lt;/em&gt;. This is controlled by peek-lock settlement, covered next.&lt;/p&gt;
&lt;h2&gt;2. Peek-lock settlement and redelivery&lt;/h2&gt;
&lt;p&gt;In peek-lock mode, a received message is locked (default lock duration 30 seconds, max 5 minutes). You then settle it:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;th&gt;Effect&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Complete&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Message is removed. Success.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Abandon&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Lock is released; the message becomes available again and &lt;strong&gt;delivery count increments&lt;/strong&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Defer&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Message stays in the queue but is only retrievable by its sequence number. Useful for out-of-order processing.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Dead-letter&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Message moves to the dead-letter queue immediately.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;(do nothing / crash / lock expires)&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;Message becomes available again and delivery count increments.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Use &lt;code&gt;ServiceBusProcessor&lt;/code&gt;, which handles concurrency, lock renewal, and settlement for you:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var processor = client.CreateProcessor(&quot;orders&quot;, new ServiceBusProcessorOptions
{
    MaxConcurrentCalls = 10,
    AutoCompleteMessages = false,          // settle explicitly
    MaxAutoLockRenewalDuration = TimeSpan.FromMinutes(10),
    PrefetchCount = 20
});

processor.ProcessMessageAsync += async args =&amp;gt;
{
    try
    {
        await HandleAsync(args.Message, args.CancellationToken);
        await args.CompleteMessageAsync(args.Message);
    }
    catch (TransientException)
    {
        // Retry: becomes visible again, delivery count + 1
        await args.AbandonMessageAsync(args.Message);
    }
    catch (PermanentException ex)
    {
        // Retrying won&#39;t help: dead-letter right away
        await args.DeadLetterMessageAsync(args.Message,
            deadLetterReason: &quot;ValidationFailed&quot;,
            deadLetterErrorDescription: ex.Message);
    }
};

processor.ProcessErrorAsync += args =&amp;gt;
{
    logger.LogError(args.Exception,
        &quot;Service Bus error from {Source} on {Entity}&quot;, args.ErrorSource, args.EntityPath);
    return Task.CompletedTask;
};

await processor.StartProcessingAsync();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Key point: &lt;strong&gt;classify failures&lt;/strong&gt;. Transient failures (timeouts, 503s from a dependency, deadlocks) should be abandoned or retried. Permanent failures (malformed payload, validation errors, missing required data) should be dead-lettered immediately, since retrying them just burns delivery attempts.&lt;/p&gt;
&lt;h3&gt;Lock duration and long processing&lt;/h3&gt;
&lt;p&gt;If processing takes longer than the lock duration, the lock expires, the message is redelivered to another consumer, and your original &lt;code&gt;Complete&lt;/code&gt; call fails with &lt;code&gt;MessageLockLost&lt;/code&gt;. Avoid this by:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Setting &lt;code&gt;MaxAutoLockRenewalDuration&lt;/code&gt; so the processor renews the lock automatically&lt;/li&gt;
&lt;li&gt;Setting an appropriate lock duration on the entity&lt;/li&gt;
&lt;li&gt;Moving very long work into a durable workflow and keeping message handlers short&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Retry timing: Service Bus has no built-in backoff on redelivery&lt;/h3&gt;
&lt;p&gt;An abandoned message is available &lt;strong&gt;immediately&lt;/strong&gt;, which can cause a tight retry loop that hammers a failing dependency. Common patterns:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;In-process retry first:&lt;/strong&gt; retry transient calls with exponential backoff (Polly or &lt;code&gt;Microsoft.Extensions.Http.Resilience&lt;/code&gt;) &lt;em&gt;within&lt;/em&gt; the handler before abandoning.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scheduled re-enqueue:&lt;/strong&gt; complete the original and send a copy scheduled for later, which gives you true delayed retries:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var retry = new ServiceBusMessage(args.Message)
{
    ScheduledEnqueueTime = DateTimeOffset.UtcNow.AddSeconds(Math.Pow(2, attempt) * 10)
};
retry.ApplicationProperties[&quot;attempt&quot;] = attempt + 1;

await sender.SendMessageAsync(retry);
await args.CompleteMessageAsync(args.Message);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you do this, do the send and complete in a &lt;strong&gt;transaction&lt;/strong&gt; so you don&#39;t lose or duplicate the message (see below), and track the attempt count yourself.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Circuit breaker:&lt;/strong&gt; if a dependency is down, stop receiving for a while instead of cycling messages through delivery attempts.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;3. Dead-letter queues (DLQ)&lt;/h2&gt;
&lt;p&gt;Every queue and every topic subscription has a &lt;strong&gt;dead-letter sub-queue&lt;/strong&gt;, addressed as &lt;code&gt;&amp;lt;entity&amp;gt;/$deadletterqueue&lt;/code&gt;. Messages end up there when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;MaxDeliveryCount&lt;/code&gt; is exceeded&lt;/strong&gt; (default 10). This is the &quot;poison message&quot; safety net.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;TTL expires&lt;/strong&gt; and dead-lettering on expiration is enabled (&lt;code&gt;DeadLetteringOnMessageExpiration&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Your code dead-letters explicitly&lt;/strong&gt; with a reason and description.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A subscription filter evaluation fails&lt;/strong&gt; (when configured to dead-letter on filter evaluation exceptions).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Session-related issues&lt;/strong&gt;, in some cases.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The DLQ is not automatically processed and has no TTL of its own, so messages stay until you deal with them. It also counts against the entity&#39;s size quota, so an ignored DLQ can eventually fill the queue.&lt;/p&gt;
&lt;p&gt;Reading dead-lettered messages:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var dlqReceiver = client.CreateReceiver(&quot;orders&quot;, new ServiceBusReceiverOptions
{
    SubQueue = SubQueue.DeadLetter
});

var messages = await dlqReceiver.ReceiveMessagesAsync(maxMessages: 20, TimeSpan.FromSeconds(5));
foreach (var m in messages)
{
    Console.WriteLine($&quot;{m.MessageId}: {m.DeadLetterReason} - {m.DeadLetterErrorDescription}&quot;);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For system dead-lettering, the reason is set for you (for example &lt;code&gt;MaxDeliveryCountExceeded&lt;/code&gt; or &lt;code&gt;TTLExpiredException&lt;/code&gt;). For your own dead-lettering, always set &lt;code&gt;deadLetterReason&lt;/code&gt; and &lt;code&gt;deadLetterErrorDescription&lt;/code&gt; so triage is easy.&lt;/p&gt;
&lt;h3&gt;What to do with dead-lettered messages&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Alert&lt;/strong&gt; when the DLQ message count is above zero (Azure Monitor metric &lt;code&gt;DeadletteredMessages&lt;/code&gt;, filtered by entity). Unmonitored DLQs are where messages go to be forgotten.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inspect&lt;/strong&gt; them (Service Bus Explorer in the portal or in Visual Studio, or code like the above) and read the reason.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fix the cause&lt;/strong&gt;: a bug, a bad payload, or a downstream outage that has since recovered.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Resubmit&lt;/strong&gt; after the fix: receive from the DLQ, send a clone to the original entity, then complete the DLQ copy. The Azure portal&#39;s Service Bus Explorer also supports resending dead-lettered messages.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Or discard/archive&lt;/strong&gt; messages that are genuinely invalid, recording where they went.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await foreach (var dead in dlqReceiver.ReceiveMessagesAsync())
{
    var clone = new ServiceBusMessage(dead);   // copies body and properties
    await sender.SendMessageAsync(clone);
    await dlqReceiver.CompleteMessageAsync(dead);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Automate DLQ handling with an Azure Function triggered from the DLQ path (&lt;code&gt;orders/$deadletterqueue&lt;/code&gt;) if you want logging, notification, or auto-resubmission with a retry cap.&lt;/p&gt;
&lt;h3&gt;Tuning &lt;code&gt;MaxDeliveryCount&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The default of 10 is often too high for failures that will never succeed and too low for slow-recovering dependencies.&lt;/li&gt;
&lt;li&gt;Pair it with how long a failure typically lasts. If a dependency outage can last 10 minutes and messages retry instantly, 10 attempts can be exhausted in seconds, sending healthy messages to the DLQ. This is another reason to add backoff.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;4. Duplicate messages&lt;/h2&gt;
&lt;p&gt;Duplicates arrive from two directions:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Producer-side duplicates.&lt;/strong&gt; A sender times out after the broker accepted the message and retries, so the broker gets two copies.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Consumer-side duplicates.&lt;/strong&gt; A message is delivered more than once because the lock expired, the consumer crashed after processing but before completing, or you abandoned it. This is inherent in at-least-once delivery.&lt;/p&gt;
&lt;h3&gt;Broker-side duplicate detection (producer duplicates)&lt;/h3&gt;
&lt;p&gt;Enable it when creating the queue or topic and set a detection window (default 10 minutes, max 7 days). Service Bus then discards any message whose &lt;strong&gt;&lt;code&gt;MessageId&lt;/code&gt;&lt;/strong&gt; matches one already received within the window.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await adminClient.CreateQueueAsync(new CreateQueueOptions(&quot;orders&quot;)
{
    RequiresDuplicateDetection = true,
    DuplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(30)
});

// Set a deterministic MessageId derived from the business key
var message = new ServiceBusMessage(body) { MessageId = $&quot;order-{order.Id}&quot; };
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Important details:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It only works if you set a &lt;strong&gt;stable, meaningful &lt;code&gt;MessageId&lt;/code&gt;&lt;/strong&gt;. Random GUIDs defeat it.&lt;/li&gt;
&lt;li&gt;It can only be enabled &lt;strong&gt;at entity creation time&lt;/strong&gt;. You can&#39;t turn it on later.&lt;/li&gt;
&lt;li&gt;It only covers duplicates &lt;em&gt;sent&lt;/em&gt; within the window. It does not help with redelivery to consumers.&lt;/li&gt;
&lt;li&gt;It isn&#39;t supported in the same way on partitioned or some Premium configurations. Check the current docs for your tier.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Idempotent consumers (the real solution)&lt;/h3&gt;
&lt;p&gt;Because at-least-once delivery can&#39;t be fully eliminated, make processing &lt;strong&gt;idempotent&lt;/strong&gt;, so handling a message twice has the same effect as handling it once.&lt;/p&gt;
&lt;p&gt;Common approaches:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Natural idempotency:&lt;/strong&gt; use upserts (&lt;code&gt;MERGE&lt;/code&gt;, &lt;code&gt;INSERT ... ON CONFLICT DO NOTHING&lt;/code&gt;) and &quot;set status = X&quot; rather than &quot;increment by 1.&quot;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Processed-message table (inbox pattern):&lt;/strong&gt; record &lt;code&gt;MessageId&lt;/code&gt; (or a business key) in the same database transaction as the business change. If the insert fails on a unique key, the message was already handled, so skip it and complete it.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// In one DB transaction:
//   INSERT INTO ProcessedMessages (MessageId) VALUES (@id)   -- unique constraint
//   ... apply business change ...
// If the insert violates the constraint: already processed, so just complete the message.
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Idempotency keys on downstream calls:&lt;/strong&gt; pass a stable key to payment providers and similar APIs so they dedupe too.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Check delivery count&lt;/strong&gt; (&lt;code&gt;message.DeliveryCount &amp;gt; 1&lt;/code&gt;) as a hint that a message may have been processed before, then verify against state.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;5. Atomic operations with transactions&lt;/h2&gt;
&lt;p&gt;A common failure mode: you send a follow-up message and then crash before completing the original, producing duplicates or lost work. Service Bus &lt;strong&gt;transactions&lt;/strong&gt; group operations on the same connection so they succeed or fail together:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var client = new ServiceBusClient(fqdn, credential,
    new ServiceBusClientOptions { EnableCrossEntityTransactions = true });

var receiver = client.CreateReceiver(&quot;orders&quot;);
var sender = client.CreateSender(&quot;payments&quot;);

var message = await receiver.ReceiveMessageAsync();

using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
    await sender.SendMessageAsync(new ServiceBusMessage($&quot;charge-{message.MessageId}&quot;));
    await receiver.CompleteMessageAsync(message);
    scope.Complete();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Transactions span only Service Bus operations. They do &lt;strong&gt;not&lt;/strong&gt; include your database. For database plus message consistency, use the &lt;strong&gt;outbox pattern&lt;/strong&gt;: write the outgoing message to an outbox table in the same DB transaction as your business change, and have a separate relay publish it to Service Bus (which, combined with consumer idempotency, gives effectively-once results).&lt;/p&gt;
&lt;h2&gt;6. Ordering and sessions&lt;/h2&gt;
&lt;p&gt;If order matters, use &lt;strong&gt;sessions&lt;/strong&gt;. They give FIFO per &lt;code&gt;SessionId&lt;/code&gt; and exclusive processing by one consumer at a time. Be aware that a failing message in a session can block the rest of that session until it&#39;s dead-lettered or completed, so set a sensible &lt;code&gt;MaxDeliveryCount&lt;/code&gt; and handle poison messages.&lt;/p&gt;
&lt;h2&gt;7. Azure Functions behavior&lt;/h2&gt;
&lt;p&gt;With the Service Bus trigger:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The host calls &lt;strong&gt;Complete&lt;/strong&gt; if your function succeeds and &lt;strong&gt;Abandon&lt;/strong&gt; if it throws (when &lt;code&gt;autoCompleteMessages&lt;/code&gt; is true, the default).&lt;/li&gt;
&lt;li&gt;Delivery count and DLQ rules are the same as above, so repeated exceptions end in the DLQ after &lt;code&gt;MaxDeliveryCount&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Tune concurrency in &lt;code&gt;host.json&lt;/code&gt;:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;extensions&quot;: {
    &quot;serviceBus&quot;: {
      &quot;maxConcurrentCalls&quot;: 16,
      &quot;maxAutoLockRenewalDuration&quot;: &quot;00:10:00&quot;,
      &quot;autoCompleteMessages&quot;: true
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;ServiceBusMessageActions&lt;/code&gt; with &lt;code&gt;autoCompleteMessages: false&lt;/code&gt; if you want explicit control (dead-letter with a reason, defer, and so on).&lt;/li&gt;
&lt;li&gt;Setting &lt;code&gt;MaxDeliveryCount&lt;/code&gt; too high combined with a flaky dependency can multiply load. Use Functions&#39; built-in retry policies only for non-Service-Bus triggers; for Service Bus, rely on the broker&#39;s redelivery and delivery count.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;8. Monitoring checklist&lt;/h2&gt;
&lt;p&gt;Alert on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Dead-lettered message count&lt;/strong&gt; &amp;gt; 0&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Active message count / queue depth&lt;/strong&gt; growing steadily (consumers falling behind or failing)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Oldest message age&lt;/strong&gt; rising&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Throttled requests&lt;/strong&gt; and server errors on the namespace&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lock-lost and processing exceptions&lt;/strong&gt; in Application Insights&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Log &lt;code&gt;MessageId&lt;/code&gt;, &lt;code&gt;DeliveryCount&lt;/code&gt;, &lt;code&gt;CorrelationId&lt;/code&gt;, and the entity name in every handler so a single message can be traced across retries.&lt;/p&gt;
&lt;h2&gt;&lt;br /&gt;&lt;/h2&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/8229926690365947742/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/how-do-you-handle-retries-failures.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/8229926690365947742'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/8229926690365947742'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/how-do-you-handle-retries-failures.html' title='How do you handle retries, failures, duplicate messages, and dead-letter queues in Service Bus?'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-3935201704303935699</id><published>2026-11-06T19:30:00.000-08:00</published><updated>2026-11-06T19:30:00.121-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><title type='text'>What are Durable Functions, and when would you use them?</title><content type='html'>&lt;h1&gt;Durable Functions&lt;/h1&gt;
&lt;p&gt;Durable Functions is an extension of Azure Functions that lets you write &lt;strong&gt;stateful, long-running workflows as code&lt;/strong&gt; in a serverless environment. Normal functions are stateless and short-lived. Durable Functions adds orchestration on top: you write a function that calls other functions in sequence or in parallel, waits for events or timers, and survives restarts, scale-out, and crashes without losing its place.&lt;/p&gt;
&lt;h2&gt;Function types&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Client function:&lt;/strong&gt; starts, queries, signals, or terminates orchestration instances (usually an HTTP, queue, or timer trigger).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Orchestrator function:&lt;/strong&gt; defines the workflow. It calls activities, awaits results, and decides what happens next.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Activity function:&lt;/strong&gt; a unit of work (call an API, write to a DB). This is where the actual I/O happens.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Entity function (Durable Entities):&lt;/strong&gt; a small piece of named, addressable state (a counter, a shopping cart) with operations you can signal or call.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;How it works&lt;/h2&gt;
&lt;p&gt;Durable Functions uses &lt;strong&gt;event sourcing&lt;/strong&gt; and &lt;strong&gt;replay&lt;/strong&gt;. Each step the orchestrator takes is recorded in a history table in the configured storage backend. When an orchestrator awaits something (an activity result, a timer, an external event), it is &lt;strong&gt;unloaded from memory&lt;/strong&gt;, so you pay for nothing while it waits. When the awaited thing completes, the orchestrator is reloaded and &lt;strong&gt;replays from the start&lt;/strong&gt;, using the recorded history to skip work already done, until it reaches the next new step.&lt;/p&gt;
&lt;p&gt;This is why orchestrator code has strict rules (see below).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Storage backends:&lt;/strong&gt; Azure Storage (default), the &lt;strong&gt;Netherite&lt;/strong&gt; backend (high throughput, uses Event Hubs and page blobs), and the &lt;strong&gt;Microsoft SQL&lt;/strong&gt; backend (state in SQL Server or Azure SQL). The &lt;strong&gt;Durable Task Scheduler&lt;/strong&gt; is a newer managed backend; check the current docs for availability and status.&lt;/p&gt;
&lt;h2&gt;Example (C# isolated worker): function chaining&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public static class OrderWorkflow
{
    [Function(&quot;OrderOrchestrator&quot;)]
    public static async Task&amp;lt;string&amp;gt; RunOrchestrator(
        [OrchestrationTrigger] TaskOrchestrationContext context)
    {
        var order = context.GetInput&amp;lt;Order&amp;gt;();

        await context.CallActivityAsync(&quot;ReserveInventory&quot;, order);
        await context.CallActivityAsync(&quot;ChargePayment&quot;, order);
        await context.CallActivityAsync(&quot;SendConfirmation&quot;, order);

        return $&quot;Order {order.Id} completed&quot;;
    }

    [Function(&quot;ReserveInventory&quot;)]
    public static Task ReserveInventory([ActivityTrigger] Order order, FunctionContext ctx)
    {
        // call inventory service
        return Task.CompletedTask;
    }

    // ChargePayment and SendConfirmation follow the same pattern
}

public static class Starter
{
    [Function(&quot;StartOrder&quot;)]
    public static async Task&amp;lt;HttpResponseData&amp;gt; Start(
        [HttpTrigger(AuthorizationLevel.Function, &quot;post&quot;)] HttpRequestData req,
        [DurableClient] DurableTaskClient client)
    {
        var order = await req.ReadFromJsonAsync&amp;lt;Order&amp;gt;();
        string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
            &quot;OrderOrchestrator&quot;, order);

        return await client.CreateCheckStatusResponseAsync(req, instanceId);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The starter returns an HTTP 202 with status-query URLs, so callers can poll for progress.&lt;/p&gt;
&lt;h2&gt;Common patterns&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;1. Function chaining:&lt;/strong&gt; run steps in order, passing output to the next (above).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Fan-out/fan-in:&lt;/strong&gt; run many activities in parallel and aggregate the results.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var tasks = files.Select(f =&amp;gt; context.CallActivityAsync&amp;lt;int&amp;gt;(&quot;ProcessFile&quot;, f));
int[] results = await Task.WhenAll(tasks);
int total = results.Sum();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;3. Async HTTP API:&lt;/strong&gt; start a long operation and return a status endpoint instead of holding a connection open.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4. Monitor:&lt;/strong&gt; poll something repeatedly until a condition is met, with flexible intervals (a durable timer loop instead of a fragile timer trigger).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;5. Human interaction / approval:&lt;/strong&gt; wait for an external event with a timeout.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using var cts = new CancellationTokenSource();
var approval = context.WaitForExternalEvent&amp;lt;bool&amp;gt;(&quot;Approval&quot;);
var timeout = context.CreateTimer(context.CurrentUtcDateTime.AddDays(3), cts.Token);

if (await Task.WhenAny(approval, timeout) == approval)
{
    cts.Cancel();   // cancel the timer so the orchestration can complete
    // approved or rejected
}
else
{
    // escalate
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;6. Aggregator (stateful entities):&lt;/strong&gt; accumulate state from many sources into one addressable entity.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;7. Saga / compensation:&lt;/strong&gt; if a later step fails, run compensating activities (refund payment, release inventory) in a &lt;code&gt;catch&lt;/code&gt; block.&lt;/p&gt;
&lt;h2&gt;Built-in reliability features&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Automatic retries&lt;/strong&gt; for activities with configurable backoff.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Durable timers&lt;/strong&gt; that can wait minutes, days, or longer at no compute cost.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sub-orchestrations&lt;/strong&gt; to compose workflows from smaller ones.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Checkpointing:&lt;/strong&gt; if the host crashes mid-workflow, it resumes from the last completed step.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Instance management APIs:&lt;/strong&gt; query, suspend, resume, terminate, rewind, and purge instances.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Orchestrator code constraints&lt;/h2&gt;
&lt;p&gt;Because the orchestrator is replayed, its code must be &lt;strong&gt;deterministic&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Don&#39;t use &lt;code&gt;DateTime.UtcNow&lt;/code&gt;; use &lt;code&gt;context.CurrentUtcDateTime&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Don&#39;t use &lt;code&gt;Guid.NewGuid()&lt;/code&gt;; use &lt;code&gt;context.NewGuid()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Don&#39;t do I/O (HTTP, DB, file access) or read changing config in the orchestrator; do that in &lt;strong&gt;activities&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Don&#39;t use &lt;code&gt;Task.Delay&lt;/code&gt; or &lt;code&gt;Thread.Sleep&lt;/code&gt;; use &lt;code&gt;context.CreateTimer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Don&#39;t use threads or non-durable async constructs; only await durable tasks.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;context.CreateReplaySafeLogger(...)&lt;/code&gt; so logs aren&#39;t duplicated on every replay.&lt;/li&gt;
&lt;li&gt;Keep inputs, outputs, and history small. Large payloads bloat storage; pass references (blob URLs, IDs) instead.&lt;/li&gt;
&lt;li&gt;Version carefully. Changing orchestrator logic while instances are in flight can break replay, so use versioning strategies or drain running instances first.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;When to use Durable Functions&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Good fits:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Multi-step business processes&lt;/strong&gt; that must complete reliably (order fulfillment, onboarding, provisioning)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Long-running workflows&lt;/strong&gt; lasting minutes to days or longer&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Human-in-the-loop&lt;/strong&gt; approvals with timeouts and escalation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Parallel batch processing&lt;/strong&gt; with aggregation (process thousands of files, then summarize)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Saga-style transactions&lt;/strong&gt; across services that need compensation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Polling and monitoring&lt;/strong&gt; loops&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Replacing hand-rolled state machines&lt;/strong&gt; built from queues and tables&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Consider something else when:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The work is &lt;strong&gt;a single short operation&lt;/strong&gt;. A plain function is simpler.&lt;/li&gt;
&lt;li&gt;You need &lt;strong&gt;very high-throughput, ultra-low-latency&lt;/strong&gt; processing. Orchestration adds storage round-trips, so look at plain queue triggers, Event Hubs, or the Netherite backend.&lt;/li&gt;
&lt;li&gt;You want a &lt;strong&gt;low-code, visual designer&lt;/strong&gt; with many connectors. &lt;strong&gt;Logic Apps&lt;/strong&gt; fits better.&lt;/li&gt;
&lt;li&gt;The workflow is &lt;strong&gt;complex enough to need a dedicated engine&lt;/strong&gt; with rich versioning, search, and visibility. Temporal or a similar engine may fit, though it brings more operational work.&lt;/li&gt;
&lt;li&gt;You need &lt;strong&gt;strict message ordering, sessions, and broker features&lt;/strong&gt;. Service Bus is the better primitive, possibly alongside Durable Functions.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Durable Functions vs. related options&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Durable Functions&lt;/th&gt;
&lt;th&gt;Logic Apps&lt;/th&gt;
&lt;th&gt;Service Bus + Functions&lt;/th&gt;
&lt;th&gt;Plain Functions&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Style&lt;/td&gt;
&lt;td&gt;Code-first workflows&lt;/td&gt;
&lt;td&gt;Visual/low-code designer&lt;/td&gt;
&lt;td&gt;Messaging between steps&lt;/td&gt;
&lt;td&gt;Single stateless step&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;State&lt;/td&gt;
&lt;td&gt;Managed for you&lt;/td&gt;
&lt;td&gt;Managed for you&lt;/td&gt;
&lt;td&gt;You manage it&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Long waits, timers, approvals&lt;/td&gt;
&lt;td&gt;Built in&lt;/td&gt;
&lt;td&gt;Built in&lt;/td&gt;
&lt;td&gt;Manual&lt;/td&gt;
&lt;td&gt;Manual&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Complex logic and loops&lt;/td&gt;
&lt;td&gt;Natural, it&#39;s just code&lt;/td&gt;
&lt;td&gt;Possible, harder to maintain&lt;/td&gt;
&lt;td&gt;Scattered across handlers&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Developers coding complex workflows&lt;/td&gt;
&lt;td&gt;Integration with many SaaS connectors&lt;/td&gt;
&lt;td&gt;Simple decoupled processing&lt;/td&gt;
&lt;td&gt;Event handlers&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;They combine well. For instance, a Service Bus-triggered function can start an orchestration, and an orchestration can call out to Logic Apps or other services.&lt;/p&gt;
&lt;h2&gt;Operations and cost&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Monitoring:&lt;/strong&gt; Application Insights captures orchestration history and traces. Use the instance management APIs, Durable Functions Monitor, or the Durable Task Scheduler dashboard (where available) to inspect state.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cost:&lt;/strong&gt; you pay for function execution plus storage transactions for state. Chatty orchestrations with many tiny activities can drive up storage costs, so batch work sensibly.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hosting:&lt;/strong&gt; works on Consumption, Flex Consumption, Premium, and Dedicated plans. Check current docs for backend support on each plan.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Housekeeping:&lt;/strong&gt; purge completed instance history periodically so storage doesn&#39;t grow without bound.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Quick rule of thumb&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;If your workflow is &lt;strong&gt;&quot;do A, then B, then C, maybe wait for something, and don&#39;t lose my place if something crashes&quot;&lt;/strong&gt;, use Durable Functions.&lt;/li&gt;
&lt;li&gt;If it is &lt;strong&gt;&quot;react to one event and do one thing&quot;&lt;/strong&gt;, use a normal function.&lt;/li&gt;
&lt;li&gt;If you want to &lt;strong&gt;click together connectors&lt;/strong&gt;, use Logic Apps.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/3935201704303935699/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/what-are-durable-functions-and-when.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/3935201704303935699'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/3935201704303935699'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/what-are-durable-functions-and-when.html' title='What are Durable Functions, and when would you use them?'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-1458370622366607924</id><published>2026-11-05T19:30:00.000-08:00</published><updated>2026-11-05T19:30:00.168-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><title type='text'>What is Azure API Management (APIM), and why do we use it? </title><content type='html'>&lt;h1&gt;Azure API Management (APIM)&lt;/h1&gt;
&lt;p&gt;Azure API Management is a managed service that sits in front of your APIs as a gateway. Clients call APIM, and APIM applies policies (authentication, rate limiting, transformation, caching) before forwarding requests to your backends. The backends can be App Service, Functions, AKS, Container Apps, on-premises systems, or even other clouds.&lt;/p&gt;
&lt;h2&gt;The three components&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Gateway:&lt;/strong&gt; the runtime proxy that receives API calls, enforces policies, and routes to backends. This is the data plane.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Management plane:&lt;/strong&gt; the Azure portal, CLI, Bicep, or REST API, where you define APIs, products, policies, and users.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Developer portal:&lt;/strong&gt; an auto-generated, customizable website where API consumers browse docs, try calls, and get subscription keys.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Self-hosted gateway:&lt;/strong&gt; you can also run the gateway in containers on-premises or in other clouds, managed from the same APIM instance (Developer and Premium tiers).&lt;/p&gt;
&lt;h2&gt;Core concepts&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;API:&lt;/strong&gt; a set of operations (e.g., &lt;code&gt;GET /orders/{id}&lt;/code&gt;), imported from OpenAPI, WSDL, an App Service, a Function App, or created manually.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Product:&lt;/strong&gt; a bundle of APIs with its own terms, quotas, and visibility (e.g., &quot;Free&quot; vs. &quot;Premium&quot; plans).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Subscription:&lt;/strong&gt; a key a consumer uses to access a product or API (sent in the &lt;code&gt;Ocp-Apim-Subscription-Key&lt;/code&gt; header by default).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Policy:&lt;/strong&gt; XML statements that run on the request or response pipeline at global, product, API, or operation scope.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Named values:&lt;/strong&gt; configuration and secrets used inside policies (can be backed by Key Vault).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Backend:&lt;/strong&gt; a reusable definition of a downstream service, with URL, credentials, and circuit breaker settings.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Why use it&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;1. Security at the edge&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Validate JWTs from Entra ID before requests reach your backend&lt;/li&gt;
&lt;li&gt;Enforce subscription keys, client certificates, and IP filtering&lt;/li&gt;
&lt;li&gt;Authenticate to backends with managed identity, so backends never expose public credentials&lt;/li&gt;
&lt;li&gt;Centralize security policies instead of re-implementing them in every service&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;2. Traffic control&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Rate limiting and quotas per client, per key, or per IP&lt;/li&gt;
&lt;li&gt;Protection against abusive callers and backend overload&lt;/li&gt;
&lt;li&gt;Response caching to reduce backend load and latency&lt;/li&gt;
&lt;li&gt;Retry and circuit breaker behavior for flaky backends&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;3. A single, consistent front door&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;One public URL and domain across many backend services&lt;/li&gt;
&lt;li&gt;Backends can move or be replaced without breaking consumers&lt;/li&gt;
&lt;li&gt;Consistent URL structure, headers, and error formats&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;4. Versioning and lifecycle&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Run multiple versions (&lt;code&gt;/v1&lt;/code&gt;, &lt;code&gt;/v2&lt;/code&gt;) side by side&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Revisions&lt;/strong&gt; let you make non-breaking changes and test them before making them current&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;5. Transformation and mediation&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Rewrite URLs, add or strip headers, convert XML to JSON, mask fields in responses&lt;/li&gt;
&lt;li&gt;Expose a clean API over a messy legacy backend without changing it&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;6. Observability&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Built-in analytics, plus diagnostic logs and traces to Application Insights and Azure Monitor&lt;/li&gt;
&lt;li&gt;Correlation IDs, per-API and per-consumer usage and latency&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;7. Developer experience and monetization&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Self-service portal with documentation and a test console&lt;/li&gt;
&lt;li&gt;Products and subscriptions let you onboard partners, issue keys, and apply different limits per tier&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Example policies&lt;/h2&gt;
&lt;p&gt;Validate an Entra ID token, rate limit, and forward using managed identity:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-xml&quot;&gt;&amp;lt;policies&amp;gt;
  &amp;lt;inbound&amp;gt;
    &amp;lt;base /&amp;gt;
    &amp;lt;validate-jwt header-name=&quot;Authorization&quot; failed-validation-httpcode=&quot;401&quot;
                  failed-validation-error-message=&quot;Unauthorized&quot;&amp;gt;
      &amp;lt;openid-config url=&quot;https://login.microsoftonline.com/&amp;lt;tenant-id&amp;gt;/v2.0/.well-known/openid-configuration&quot; /&amp;gt;
      &amp;lt;audiences&amp;gt;
        &amp;lt;audience&amp;gt;api://&amp;lt;api-client-id&amp;gt;&amp;lt;/audience&amp;gt;
      &amp;lt;/audiences&amp;gt;
      &amp;lt;required-claims&amp;gt;
        &amp;lt;claim name=&quot;roles&quot; match=&quot;any&quot;&amp;gt;
          &amp;lt;value&amp;gt;Orders.Read&amp;lt;/value&amp;gt;
        &amp;lt;/claim&amp;gt;
      &amp;lt;/required-claims&amp;gt;
    &amp;lt;/validate-jwt&amp;gt;

    &amp;lt;rate-limit-by-key calls=&quot;100&quot; renewal-period=&quot;60&quot;
                       counter-key=&quot;@(context.Request.IpAddress)&quot; /&amp;gt;

    &amp;lt;authentication-managed-identity resource=&quot;api://&amp;lt;backend-client-id&amp;gt;&quot; /&amp;gt;
  &amp;lt;/inbound&amp;gt;
  &amp;lt;backend&amp;gt;
    &amp;lt;base /&amp;gt;
  &amp;lt;/backend&amp;gt;
  &amp;lt;outbound&amp;gt;
    &amp;lt;base /&amp;gt;
    &amp;lt;set-header name=&quot;X-Powered-By&quot; exists-action=&quot;delete&quot; /&amp;gt;
  &amp;lt;/outbound&amp;gt;
  &amp;lt;on-error&amp;gt;
    &amp;lt;base /&amp;gt;
  &amp;lt;/on-error&amp;gt;
&amp;lt;/policies&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Response caching:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-xml&quot;&gt;&amp;lt;inbound&amp;gt;
  &amp;lt;base /&amp;gt;
  &amp;lt;cache-lookup vary-by-developer=&quot;false&quot; vary-by-developer-groups=&quot;false&quot; /&amp;gt;
&amp;lt;/inbound&amp;gt;
&amp;lt;outbound&amp;gt;
  &amp;lt;base /&amp;gt;
  &amp;lt;cache-store duration=&quot;60&quot; /&amp;gt;
&amp;lt;/outbound&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Tiers&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tier&lt;/th&gt;
&lt;th&gt;Typical use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Consumption&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Serverless, pay per call, scale to zero; good for low or spiky traffic (no VNet injection, limited features)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Developer&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Non-production, for evaluation and testing (no SLA)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Basic / Standard&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Small to mid-sized production workloads (classic tiers)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Premium&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Multi-region, availability zones, VNet injection, self-hosted gateway, highest scale&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;v2 tiers (Basic v2, Standard v2, Premium v2)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Newer generation with faster provisioning and scaling, and simpler VNet integration&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Tier names and feature sets change over time, so check the current pricing and feature comparison before choosing.&lt;/p&gt;
&lt;h2&gt;Typical architecture&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;Client ─► Front Door / App Gateway (WAF) ─► APIM ─► Backends
                                              │       ├─ App Service (Orders API)
                                              │       ├─ Functions (Webhooks)
                                              │       └─ AKS / Container Apps (Inventory)
                                              └─► Application Insights
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Lock backends down so they only accept traffic from APIM (access restrictions, private endpoints, or a shared header or token check). Otherwise callers can bypass your policies by hitting the backend directly.&lt;/p&gt;
&lt;h2&gt;When APIM is a good fit&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;You expose APIs to &lt;strong&gt;external partners or the public&lt;/strong&gt; and need keys, quotas, and a developer portal&lt;/li&gt;
&lt;li&gt;You have &lt;strong&gt;multiple backend services&lt;/strong&gt; and want one consistent entry point&lt;/li&gt;
&lt;li&gt;You need &lt;strong&gt;centralized auth, throttling, and logging&lt;/strong&gt; without changing each service&lt;/li&gt;
&lt;li&gt;You&#39;re &lt;strong&gt;modernizing legacy services&lt;/strong&gt; and want to hide their quirks behind a clean facade&lt;/li&gt;
&lt;li&gt;You need to &lt;strong&gt;publish APIs across regions or hybrid environments&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;When it may be overkill&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;single internal API&lt;/strong&gt; with one consumer, where app-level auth and Easy Auth suffice&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Very low-budget or prototype&lt;/strong&gt; projects (the non-Consumption tiers carry a meaningful fixed monthly cost)&lt;/li&gt;
&lt;li&gt;Scenarios needing &lt;strong&gt;only WAF and routing&lt;/strong&gt;, where Front Door or Application Gateway is simpler&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Latency-critical hot paths&lt;/strong&gt;, where every extra hop matters (APIM adds some overhead, usually small)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;APIM vs. related services&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;APIM&lt;/th&gt;
&lt;th&gt;Front Door / App Gateway&lt;/th&gt;
&lt;th&gt;Easy Auth&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Focus&lt;/td&gt;
&lt;td&gt;API lifecycle, policy, consumer management&lt;/td&gt;
&lt;td&gt;Global routing, WAF, load balancing&lt;/td&gt;
&lt;td&gt;Simple built-in authentication&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Understands API operations and products&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Rate limiting per consumer/key&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Basic (WAF rate rules)&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Developer portal&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;They&#39;re complementary: Front Door provides global entry and WAF, and APIM provides API governance behind it.&lt;/p&gt;
&lt;h2&gt;Good practices:&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Define APIM as code&lt;/strong&gt; (Bicep or Terraform, with policies in versioned files) and deploy through CI/CD. Use the APIOps approach to promote API definitions between environments.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use managed identity&lt;/strong&gt; for backend authentication, and &lt;strong&gt;Key Vault-backed named values&lt;/strong&gt; for secrets.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Validate tokens in APIM and also in the backend&lt;/strong&gt; (defense in depth), and restrict backends to APIM traffic only.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Keep policies simple and reusable&lt;/strong&gt; with fragments, because complex policy logic is hard to test and debug.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Send diagnostics to Application Insights&lt;/strong&gt; and watch for gateway versus backend latency and failures.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use revisions and versions&lt;/strong&gt; deliberately: revisions for non-breaking changes, versions for breaking ones.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Plan capacity and region placement&lt;/strong&gt;: choose a tier that supports the VNet and availability needs you actually have, because some of these can&#39;t be changed later without redeploying.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/1458370622366607924/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/what-is-azure-api-management-apim-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/1458370622366607924'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/1458370622366607924'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/what-is-azure-api-management-apim-and.html' title='What is Azure API Management (APIM), and why do we use it? '/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-3592729807470198170</id><published>2026-11-04T19:30:00.000-08:00</published><updated>2026-11-04T19:30:00.124-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><title type='text'>What deployment options are available for a Web API in Azure—App Service or AKS? </title><content type='html'>&lt;h1&gt;Deployment Options for a Web API in Azure&lt;/h1&gt;
&lt;p&gt;App Service and AKS sit at opposite ends of a spectrum: &lt;strong&gt;App Service&lt;/strong&gt; is a managed platform where you deploy code or a container and Azure runs everything else, while &lt;strong&gt;AKS&lt;/strong&gt; is managed Kubernetes where you get full control of the orchestration layer and take on the operational work that comes with it. There are also middle-ground options, covered below.&lt;/p&gt;
&lt;h2&gt;App Service&lt;/h2&gt;
&lt;p&gt;A PaaS for web apps and APIs. You deploy code (zip, Git, CI/CD) or a single container, and Azure handles the OS, patching, load balancing, TLS, and scaling.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Strengths:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Fastest path to production, with very little operational overhead&lt;/li&gt;
&lt;li&gt;Built-in deployment slots (Standard tier and above) for zero-downtime swaps and instant rollback&lt;/li&gt;
&lt;li&gt;Autoscale, custom domains, managed certificates, Easy Auth, VNet integration, and managed identity&lt;/li&gt;
&lt;li&gt;Native .NET support, with no Dockerfile required&lt;/li&gt;
&lt;li&gt;A predictable, per-plan price&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Limitations:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Less control over networking, scheduling, and the runtime environment&lt;/li&gt;
&lt;li&gt;Multi-container setups are limited. It&#39;s one app per container, with no real orchestration&lt;/li&gt;
&lt;li&gt;Not suited to complex microservice meshes, sidecars, or custom operators&lt;/li&gt;
&lt;li&gt;Scale is bounded by plan limits (though it&#39;s plenty for most APIs)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Deploying:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az webapp up --name my-api --resource-group my-rg --runtime &quot;dotnet:8&quot;
# or, in CI/CD: azure/webapps-deploy@v3 with a staging slot, then swap
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;AKS (Azure Kubernetes Service)&lt;/h2&gt;
&lt;p&gt;Managed Kubernetes. Azure runs the control plane, and you manage the workloads, node pools, networking, ingress, and upgrades. &lt;strong&gt;AKS Automatic&lt;/strong&gt; is a newer mode that manages more for you (node provisioning, scaling, and defaults), which narrows the gap with simpler platforms.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Strengths:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Full Kubernetes ecosystem: Helm, operators, service meshes, GitOps, custom controllers&lt;/li&gt;
&lt;li&gt;Fine-grained control over scheduling, networking, resource limits, and node types (including GPU or spot nodes)&lt;/li&gt;
&lt;li&gt;Good for many services, sidecars, and portability across clouds&lt;/li&gt;
&lt;li&gt;Efficient bin-packing of many workloads onto shared nodes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Limitations:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Real operational burden: cluster upgrades, node patching, ingress, certificates, observability, and security hardening&lt;/li&gt;
&lt;li&gt;Needs Kubernetes expertise on the team&lt;/li&gt;
&lt;li&gt;You must containerize everything&lt;/li&gt;
&lt;li&gt;Costs include the nodes (paid whether busy or idle) plus the effort to run the platform&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Deploying:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az acr build --registry myacr --image my-api:1.0.0 .
az aks get-credentials --name my-aks --resource-group my-rg
kubectl apply -f deployment.yaml
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;apiVersion: apps/v1
kind: Deployment
metadata: { name: my-api }
spec:
  replicas: 3
  selector: { matchLabels: { app: my-api } }
  template:
    metadata: { labels: { app: my-api } }
    spec:
      containers:
      - name: my-api
        image: myacr.azurecr.io/my-api:1.0.0
        ports: [{ containerPort: 8080 }]
        readinessProbe: { httpGet: { path: /health, port: 8080 } }
        resources:
          requests: { cpu: 250m, memory: 256Mi }
          limits: { memory: 512Mi }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You&#39;d also add a Service and an Ingress (for example, Application Gateway for Containers or NGINX), use &lt;strong&gt;workload identity&lt;/strong&gt; for Azure access, and roll out with Helm or Flux/Argo CD.&lt;/p&gt;
&lt;h2&gt;Side-by-side&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;App Service&lt;/th&gt;
&lt;th&gt;AKS&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Model&lt;/td&gt;
&lt;td&gt;PaaS, you deploy an app&lt;/td&gt;
&lt;td&gt;Managed Kubernetes, you run workloads&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Packaging&lt;/td&gt;
&lt;td&gt;Code or container&lt;/td&gt;
&lt;td&gt;Container (required)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Operational effort&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Learning curve&lt;/td&gt;
&lt;td&gt;Gentle&lt;/td&gt;
&lt;td&gt;Steep&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scaling&lt;/td&gt;
&lt;td&gt;Autoscale rules, per plan&lt;/td&gt;
&lt;td&gt;Pod autoscaling (HPA/KEDA) plus node autoscaling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Zero-downtime release&lt;/td&gt;
&lt;td&gt;Deployment slots&lt;/td&gt;
&lt;td&gt;Rolling updates, canary, blue/green via ingress or mesh&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Networking control&lt;/td&gt;
&lt;td&gt;Moderate (VNet integration, private endpoints)&lt;/td&gt;
&lt;td&gt;Very high (CNI options, network policies, service mesh)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multi-service / microservices&lt;/td&gt;
&lt;td&gt;Possible, one plan hosting many apps&lt;/td&gt;
&lt;td&gt;Native fit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cost model&lt;/td&gt;
&lt;td&gt;Pay per plan&lt;/td&gt;
&lt;td&gt;Pay for nodes, plus platform effort&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Typical APIs and web apps&lt;/td&gt;
&lt;td&gt;Large, complex, multi-service platforms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Other options worth considering&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Azure Container Apps:&lt;/strong&gt; serverless containers built on Kubernetes (with KEDA and Dapr) but without cluster management. Supports scale-to-zero, revisions with traffic splitting, and event-driven scaling. For many teams it&#39;s the best middle ground between App Service and AKS.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Azure Functions:&lt;/strong&gt; for small, event-driven, or bursty APIs where per-execution billing and scale-to-zero make sense.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;App Service Environment (ASE v3):&lt;/strong&gt; single-tenant, VNet-injected App Service for strict isolation and compliance needs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Azure Container Instances:&lt;/strong&gt; simple, short-lived containers. Rarely the right choice for a production API on its own.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Virtual Machines:&lt;/strong&gt; only if you need OS-level control or have legacy requirements.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;How to choose&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A single API or a handful, a small or mid-sized team, and you want to ship quickly&lt;/strong&gt; → &lt;strong&gt;App Service&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Containerized microservices, but you don&#39;t want to run Kubernetes&lt;/strong&gt; → &lt;strong&gt;Container Apps&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Spiky or event-driven workloads, minimal API surface&lt;/strong&gt; → &lt;strong&gt;Functions&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dozens of services, a platform team, a need for service mesh, operators, custom scheduling, or multi-cloud portability&lt;/strong&gt; → &lt;strong&gt;AKS&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Strict network isolation or compliance requirements on a PaaS model&lt;/strong&gt; → &lt;strong&gt;App Service Environment&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A practical rule: &lt;strong&gt;start with App Service (or Container Apps) and move to AKS only when you hit a concrete limit.&lt;/strong&gt; Teams often adopt AKS for the flexibility they imagine they&#39;ll need, then spend a lot of effort on cluster operations that App Service would have handled. Because both can run the same container image, moving later is less painful if you containerize from the start.&lt;/p&gt;
&lt;h2&gt;Cross-cutting concerns (the same on all of them)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;managed identity&lt;/strong&gt; and &lt;strong&gt;Key Vault&lt;/strong&gt; instead of stored credentials.&lt;/li&gt;
&lt;li&gt;Put &lt;strong&gt;APIM, Front Door, or Application Gateway&lt;/strong&gt; in front for routing, WAF, and rate limiting.&lt;/li&gt;
&lt;li&gt;Send telemetry to &lt;strong&gt;Application Insights&lt;/strong&gt; and define health checks and alerts.&lt;/li&gt;
&lt;li&gt;Deploy through &lt;strong&gt;CI/CD&lt;/strong&gt; with infrastructure as code (Bicep or Terraform).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/3592729807470198170/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/what-deployment-options-are-available.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/3592729807470198170'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/3592729807470198170'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/what-deployment-options-are-available.html' title='What deployment options are available for a Web API in Azure—App Service or AKS? '/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-6619683076499236468</id><published>2026-11-03T19:30:00.000-08:00</published><updated>2026-11-03T19:30:00.124-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><title type='text'>How do you implement CI/CD for a .NET application in Azure?</title><content type='html'>&lt;h1&gt;CI/CD for a .NET Application in Azure&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;CI&lt;/strong&gt; (continuous integration) builds and tests every change automatically. &lt;strong&gt;CD&lt;/strong&gt; (continuous delivery/deployment) ships the tested build through environments to production in a repeatable, low-risk way. The two common tool choices are &lt;strong&gt;GitHub Actions&lt;/strong&gt; and &lt;strong&gt;Azure Pipelines (Azure DevOps)&lt;/strong&gt;. The structure is the same in both.&lt;/p&gt;
&lt;h2&gt;The pipeline shape&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;Commit/PR ─► Build ─► Test ─► Publish artifact ─► Deploy Dev ─► Deploy Staging ─► (approval) ─► Production
                                  (build once)                    (slot / test)                  (swap)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Principles:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Build once, deploy the same artifact everywhere.&lt;/strong&gt; Don&#39;t rebuild per environment. Differences come from configuration, not code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Run tests on every PR&lt;/strong&gt; and block merges when they fail (branch protection).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No stored credentials.&lt;/strong&gt; Authenticate to Azure with OIDC (workload identity federation).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Gate production&lt;/strong&gt; with approvals and automated checks.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Option 1: GitHub Actions&lt;/h2&gt;
&lt;h3&gt;One-time setup: passwordless Azure login&lt;/h3&gt;
&lt;p&gt;Create an app registration (or user-assigned managed identity), add a &lt;strong&gt;federated credential&lt;/strong&gt; trusting your repo, and grant it a role on the target scope.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# App registration + service principal
az ad app create --display-name gh-deploy-my-app
az ad sp create --id &amp;lt;appId&amp;gt;

# Trust GitHub Actions for the main branch
az ad app federated-credential create --id &amp;lt;appId&amp;gt; --parameters &#39;{
  &quot;name&quot;: &quot;gh-main&quot;,
  &quot;issuer&quot;: &quot;https://token.actions.githubusercontent.com&quot;,
  &quot;subject&quot;: &quot;repo:my-org/my-repo:environment:production&quot;,
  &quot;audiences&quot;: [&quot;api://AzureADTokenExchange&quot;]
}&#39;

# Least-privilege role at resource group scope
az role assignment create --assignee &amp;lt;appId&amp;gt; --role &quot;Website Contributor&quot; \
  --scope /subscriptions/&amp;lt;sub-id&amp;gt;/resourceGroups/my-rg
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;subject&lt;/code&gt; must match how the workflow runs. For jobs using a GitHub &lt;strong&gt;environment&lt;/strong&gt;, use &lt;code&gt;environment:&amp;lt;name&amp;gt;&lt;/code&gt;. For branch-based runs, use &lt;code&gt;ref:refs/heads/main&lt;/code&gt;. You need one federated credential per subject.&lt;/p&gt;
&lt;p&gt;Store &lt;code&gt;AZURE_CLIENT_ID&lt;/code&gt;, &lt;code&gt;AZURE_TENANT_ID&lt;/code&gt;, and &lt;code&gt;AZURE_SUBSCRIPTION_ID&lt;/code&gt; as repository secrets or variables. They&#39;re identifiers, not credentials.&lt;/p&gt;
&lt;h3&gt;Workflow&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;name: ci-cd

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

permissions:
  id-token: write   # needed for OIDC
  contents: read

jobs:
  build-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-dotnet@v4
        with:
          dotnet-version: &#39;8.0.x&#39;

      - run: dotnet restore
      - run: dotnet build --no-restore -c Release
      - run: dotnet test --no-build -c Release --logger trx --collect:&quot;XPlat Code Coverage&quot;

      - run: dotnet publish src/MyApi/MyApi.csproj -c Release -o ./publish --no-build

      - uses: actions/upload-artifact@v4
        with:
          name: api
          path: ./publish

  deploy-staging:
    needs: build-test
    if: github.ref == &#39;refs/heads/main&#39;   # PRs build and test only
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - uses: actions/download-artifact@v4
        with: { name: api, path: ./publish }

      - uses: azure/login@v2
        with:
          client-id: ${{ secrets.AZURE_CLIENT_ID }}
          tenant-id: ${{ secrets.AZURE_TENANT_ID }}
          subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

      - uses: azure/webapps-deploy@v3
        with:
          app-name: my-api
          slot-name: staging
          package: ./publish

      - name: Smoke test
        run: curl --fail --retry 5 --retry-delay 5 https://my-api-staging.azurewebsites.net/health

  deploy-production:
    needs: deploy-staging
    runs-on: ubuntu-latest
    environment: production        # configure required reviewers on this environment
    steps:
      - uses: azure/login@v2
        with:
          client-id: ${{ secrets.AZURE_CLIENT_ID }}
          tenant-id: ${{ secrets.AZURE_TENANT_ID }}
          subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

      - name: Swap staging into production
        run: |
          az webapp deployment slot swap \
            --name my-api --resource-group my-rg \
            --slot staging --target-slot production
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;GitHub Environments&lt;/strong&gt; (&lt;code&gt;staging&lt;/code&gt;, &lt;code&gt;production&lt;/code&gt;) give you required reviewers, wait timers, and environment-scoped secrets.&lt;/li&gt;
&lt;li&gt;Deployment slots require &lt;strong&gt;Standard tier or above&lt;/strong&gt;. Slot swaps warm up the staging instance first, so production sees no cold start.&lt;/li&gt;
&lt;li&gt;To roll back, swap again. The previous version is still sitting in the staging slot.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Option 2: Azure Pipelines (YAML)&lt;/h2&gt;
&lt;p&gt;Create a &lt;strong&gt;service connection&lt;/strong&gt; to Azure using &lt;strong&gt;workload identity federation&lt;/strong&gt; (the recommended option over secret-based connections).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;trigger:
  branches:
    include: [main]

pool:
  vmImage: ubuntu-latest

variables:
  buildConfiguration: Release

stages:
- stage: Build
  jobs:
  - job: BuildTest
    steps:
    - task: UseDotNet@2
      inputs:
        packageType: sdk
        version: 8.0.x

    - script: dotnet restore
    - script: dotnet build --no-restore -c $(buildConfiguration)

    - task: DotNetCoreCLI@2
      displayName: Test
      inputs:
        command: test
        projects: &#39;**/*Tests.csproj&#39;
        arguments: &#39;-c $(buildConfiguration) --no-build&#39;

    - task: DotNetCoreCLI@2
      displayName: Publish
      inputs:
        command: publish
        publishWebProjects: true
        arguments: &#39;-c $(buildConfiguration) -o $(Build.ArtifactStagingDirectory)&#39;
        zipAfterPublish: true

    - publish: $(Build.ArtifactStagingDirectory)
      artifact: drop

- stage: Staging
  dependsOn: Build
  condition: and(succeeded(), eq(variables[&#39;Build.SourceBranch&#39;], &#39;refs/heads/main&#39;))
  jobs:
  - deployment: DeployStaging
    environment: staging
    strategy:
      runOnce:
        deploy:
          steps:
          - task: AzureWebApp@1
            inputs:
              azureSubscription: my-service-connection
              appType: webAppLinux
              appName: my-api
              deployToSlotOrASE: true
              resourceGroupName: my-rg
              slotName: staging
              package: $(Pipeline.Workspace)/drop/**/*.zip

- stage: Production
  dependsOn: Staging
  jobs:
  - deployment: DeployProd
    environment: production      # add Approvals and checks on this environment
    strategy:
      runOnce:
        deploy:
          steps:
          - task: AzureAppServiceManage@0
            inputs:
              azureSubscription: my-service-connection
              action: Swap Slots
              webAppName: my-api
              resourceGroupName: my-rg
              sourceSlot: staging
              targetSlot: production
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Azure DevOps &lt;strong&gt;Environments&lt;/strong&gt; provide approvals, checks, and deployment history, the same role that GitHub Environments play.&lt;/p&gt;
&lt;h2&gt;Infrastructure as Code&lt;/h2&gt;
&lt;p&gt;Don&#39;t create Azure resources by hand. Define them in &lt;strong&gt;Bicep&lt;/strong&gt; (or Terraform) and deploy them through the pipeline, so environments stay consistent and reviewable.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;- uses: azure/arm-deploy@v2
  with:
    scope: resourcegroup
    resourceGroupName: my-rg
    template: ./infra/main.bicep
    parameters: ./infra/prod.bicepparam
    failOnStdErr: false
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A common pattern is to deploy infrastructure first and the app second. Use &lt;code&gt;what-if&lt;/code&gt; on pull requests to preview infrastructure changes before merging.&lt;/p&gt;
&lt;h2&gt;Database migrations&lt;/h2&gt;
&lt;p&gt;Don&#39;t let the app run migrations on startup in production. Prefer an explicit pipeline step:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# Idempotent SQL script, reviewable and safe to re-run
dotnet ef migrations script --idempotent -o migrate.sql \
  --project src/MyApi --startup-project src/MyApi

# Or a self-contained migration bundle
dotnet ef migrations bundle -o efbundle --project src/MyApi
./efbundle --connection &quot;&amp;lt;connection-string&amp;gt;&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Authenticate to SQL with the pipeline&#39;s Entra identity rather than a password. Write migrations in an &lt;strong&gt;expand/contract&lt;/strong&gt; style (add new columns and tables first, remove old ones later) so the previous version keeps working during a slot swap or rollback.&lt;/p&gt;
&lt;h2&gt;Configuration and secrets per environment&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Keep &lt;strong&gt;non-secret settings&lt;/strong&gt; in app settings, applied per slot or environment. Mark settings that must not move during a swap as &lt;strong&gt;slot settings&lt;/strong&gt; (sticky).&lt;/li&gt;
&lt;li&gt;Store secrets in &lt;strong&gt;Key Vault&lt;/strong&gt; and use Key Vault references. Give the app a &lt;strong&gt;managed identity&lt;/strong&gt; to read them.&lt;/li&gt;
&lt;li&gt;Never put secrets in the repo or the build artifact. Use environment-scoped secrets only for pipeline identifiers.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;Azure App Configuration&lt;/strong&gt; with feature flags if you want to release code dark and enable features separately.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Containerized apps&lt;/h2&gt;
&lt;p&gt;If you deploy containers (Container Apps, AKS, App Service for Containers):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;- run: |
    az acr login --name myacr
    docker build -t myacr.azurecr.io/my-api:${{ github.sha }} .
    docker push myacr.azurecr.io/my-api:${{ github.sha }}

- run: |
    az containerapp update --name my-api --resource-group my-rg \
      --image myacr.azurecr.io/my-api:${{ github.sha }}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Tag images with the &lt;strong&gt;commit SHA&lt;/strong&gt; (never rely on &lt;code&gt;latest&lt;/code&gt;), and give the app a managed identity with the &lt;code&gt;AcrPull&lt;/code&gt; role. Container Apps &lt;strong&gt;revisions&lt;/strong&gt; let you shift traffic gradually (blue/green or canary). For AKS, use Helm or GitOps (Flux/Argo CD).&lt;/p&gt;
&lt;h2&gt;Quality and safety gates&lt;/h2&gt;
&lt;p&gt;Add these as the pipeline matures:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Static analysis and security:&lt;/strong&gt; Roslyn analyzers, &lt;code&gt;dotnet list package --vulnerable&lt;/code&gt;, Dependabot or Renovate, &lt;strong&gt;CodeQL&lt;/strong&gt;, secret scanning, and container image scanning (Defender for Cloud).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Integration tests&lt;/strong&gt; against ephemeral resources (Testcontainers or a dedicated test environment).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Post-deploy smoke tests&lt;/strong&gt; and &lt;strong&gt;health checks&lt;/strong&gt;, which block the swap if they fail.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Load or performance checks&lt;/strong&gt; on staging for critical paths.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Automated rollback&lt;/strong&gt; if post-release metrics or alerts degrade.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Branch protection:&lt;/strong&gt; required reviews, required status checks, and no direct pushes to &lt;code&gt;main&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Good practices&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Keep pipelines in the repo&lt;/strong&gt; (YAML), versioned and reviewed like code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cache NuGet packages&lt;/strong&gt; and use &lt;code&gt;--no-restore&lt;/code&gt; and &lt;code&gt;--no-build&lt;/code&gt; flags to speed up runs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use reusable workflows or templates&lt;/strong&gt; to share logic across services.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Separate subscriptions or resource groups per environment&lt;/strong&gt;, and use separate identities with least privilege for each.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Version your builds&lt;/strong&gt; (for example, with MinVer or the commit SHA) and surface the version in a &lt;code&gt;/health&lt;/code&gt; or &lt;code&gt;/version&lt;/code&gt; endpoint, so you can confirm what&#39;s running.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mark deployments in Application Insights&lt;/strong&gt; (release annotations) so you can correlate regressions with releases.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Prefer small, frequent releases&lt;/strong&gt; over large batches. They&#39;re easier to test and roll back.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Minimal starting point:&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Create a workflow that restores, builds, and tests on every PR.&lt;/li&gt;
&lt;li&gt;Add OIDC-based Azure login and deploy to a &lt;strong&gt;staging slot&lt;/strong&gt; on merge to &lt;code&gt;main&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Add a &lt;strong&gt;smoke test&lt;/strong&gt; and a &lt;strong&gt;manual approval&lt;/strong&gt; on a &lt;code&gt;production&lt;/code&gt; environment, then &lt;strong&gt;swap&lt;/strong&gt; slots.&lt;/li&gt;
&lt;li&gt;Move infrastructure into Bicep and deploy it from the pipeline.&lt;/li&gt;
&lt;li&gt;Add security scanning, migrations as a controlled step, and alerts tied to releases.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/6619683076499236468/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/how-do-you-implement-cicd-for-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/6619683076499236468'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/6619683076499236468'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/how-do-you-implement-cicd-for-net.html' title='How do you implement CI/CD for a .NET application in Azure?'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-9198073852071720309</id><published>2026-11-03T19:30:00.000-08:00</published><updated>2026-11-03T19:30:00.124-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Find employees who have the same salary as their manager.</title><content type='html'>&lt;div class=&quot;pWvJNd&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;zp3Dsd#fP0RJ&quot; jsuid=&quot;dRtJEb_5&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;div data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;z34MU#CsVNRe&quot; jsname=&quot;s7e4Od&quot; jsuid=&quot;dRtJEb_6&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;mZJni&quot; data-container-id=&quot;main-col&quot; data-ctx-provider=&quot;[[[&amp;quot;dMtGDc&amp;quot;,&amp;quot;[false]&amp;quot;]]]&quot; data-processed=&quot;true&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwju6Ou379qXAxUIzTgGHeD0BMoQ3KYQegYIAAgHEAE&quot; data-xid=&quot;VpUvz&quot; dir=&quot;ltr&quot; jsaction=&quot;cC6SSe:&amp;amp;dRtJEb_7|mNzCb;&quot; jscontroller=&quot;Aoijq#INwBm&quot; jsname=&quot;KFl8ub&quot; jsuid=&quot;dRtJEb_7&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAICxAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;dRtJEb_o&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;&lt;span data-processed=&quot;true&quot; data-subtree=&quot;aimfl&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;To find employees who earn the exact same salary as their manager, you need to &lt;/span&gt;&lt;mark class=&quot;b6AQX&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwju6Ou379qXAxUIzTgGHeD0BMoQuJAPegYIAAgLEAE&quot; data-wiz-attrbind=&quot;class=dRtJEb_q/cFwyDc&quot; jsaction=&quot;click:&amp;amp;dRtJEb_q|ZUljYd;&quot; jscontroller=&quot;l6hPId#Mt0KKb&quot; jsuid=&quot;dRtJEb_q&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;perform a &lt;span class=&quot;rQesXe MPyX&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;tP2kf#s32ZS&quot; jsuid=&quot;dRtJEb_r&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;Self-Join&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[[[null,null,null,null,null,null,null,null,null,null,null,null,[247864,null,0]]]]--&gt;&lt;/mark&gt;. This means you join the &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;dRtJEb_s&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;employees&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; table to itself—treating one instance as the &quot;Employee table&quot; and the second instance as the &quot;Manager table.&quot;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;dRtJEb_y|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;dRtJEb_y&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=dRtJEb_z/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;dRtJEb_z&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;The Query&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIDRAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;dRtJEb_10&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;The join links the employee&#39;s &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;dRtJEb_11&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;manager_id&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; to the manager&#39;s &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;dRtJEb_12&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;employee_id&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;, and the &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;dRtJEb_13&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;WHERE&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; clause filters for matching salary values:&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;dRtJEb_19|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;dRtJEb_19&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;BpxUDf aiModeUiCodeBlock__Container&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIDhAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;dRtJEb_1c,dRtJEb_1b&quot; jsaction=&quot;&quot; jscontroller=&quot;Liu6s#lcO7sb&quot; jsuid=&quot;dRtJEb_1a&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 4px 0px 0px;&quot;&gt;&lt;div data-processed=&quot;true&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;rq1a2&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 0px;&quot;&gt;&lt;div class=&quot;a2TNg&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;GlO4G&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; margin: 0px;&quot;&gt;sql&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;PGvq2d&quot; dir=&quot;ltr&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;pre style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 14px 0px;&quot;&gt;&lt;code jsuid=&quot;dRtJEb_1c&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; 
    e.employee_id &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; emp_id,
    e.employee_name &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; emp_name,
    e.salary &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; emp_salary,
    m.employee_name &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; manager_name,
    m.salary &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; manager_salary
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees e
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;INNER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;JOIN&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees m &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;ON&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; e.manager_id = m.employee_id
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;WHERE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; e.salary = m.salary;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;iMHp6c&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 3px 0px 0px;&quot;&gt;&lt;div class=&quot;ZIumpf&quot; style=&quot;border-bottom: 0px rgb(32, 33, 36); font-size: 12px; margin: 0px;&quot;&gt;Use code with caution.&lt;/div&gt;&lt;span data-ved=&quot;2ahUKEwju6Ou379qXAxUIzTgGHeD0BMoQopQPegYIAAgOEAE&quot; jsaction=&quot;action:&amp;amp;dRtJEb_1a|ZUljYd&quot; jsuid=&quot;dRtJEb_1b&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwju6Ou379qXAxUIzTgGHeD0BMoQh9gSegYIAAgOEAI&quot; jsaction=&quot;&quot; jscontroller=&quot;cXTEid#e0nEwf&quot; jsuid=&quot;dRtJEb_1d&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd||GVEHxc=*Q0pj3b|[]--&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;!--TgQPHd|||[[&amp;quot;sql&amp;quot;,&amp;quot;SELECT \n    e.employee_id AS emp_id,\n    e.employee_name AS emp_name,\n    e.salary AS emp_salary,\n    m.employee_name AS manager_name,\n    m.salary AS manager_salary\nFROM employees e\nINNER JOIN employees m ON e.manager_id \u003d m.employee_id\nWHERE e.salary \u003d m.salary;\n&amp;quot;,[[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; \n    e.employee_id &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; emp_id,\n    e.employee_name &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; emp_name,\n    e.salary &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; emp_salary,\n    m.employee_name &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; manager_name,\n    m.salary &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; manager_salary\n&amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; employees e\n&amp;quot;,0],[&amp;quot;INNER&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;JOIN&amp;quot;,3],[&amp;quot; employees m &amp;quot;,0],[&amp;quot;ON&amp;quot;,3],[&amp;quot; e.manager_id \u003d m.employee_id\n&amp;quot;,0],[&amp;quot;WHERE&amp;quot;,3],[&amp;quot; e.salary \u003d m.salary;\n&amp;quot;,0]]]]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;dRtJEb_1h|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;dRtJEb_1h&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=dRtJEb_1i/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;dRtJEb_1i&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;How It Works&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;ul class=&quot;XSq4R KI3fJ&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;wiLEJc#NS0kde&quot; jsuid=&quot;dRtJEb_1j&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;&lt;li class=&quot;Z1qcYe&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAB&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;oSLmPe#HokZ0d&quot; jsuid=&quot;dRtJEb_1k&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px 0px 12px;&quot;&gt;&lt;span class=&quot;iNqyIf&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;KdQfFc#d5Qebf&quot; jsuid=&quot;dRtJEb_1l&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;rQesXe MPyX&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;tP2kf#s32ZS&quot; jsuid=&quot;dRtJEb_1m&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;&lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;dRtJEb_1n&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;employees e&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;: Represents the table context looking down at the regular employees.&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/li&gt;&lt;li class=&quot;Z1qcYe&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAC&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;oSLmPe#HokZ0d&quot; jsuid=&quot;dRtJEb_1o&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px 0px 12px;&quot;&gt;&lt;span class=&quot;iNqyIf&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;KdQfFc#d5Qebf&quot; jsuid=&quot;dRtJEb_1p&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;rQesXe MPyX&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;tP2kf#s32ZS&quot; jsuid=&quot;dRtJEb_1q&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;&lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;dRtJEb_1r&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;employees m&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;: Represents the table context looking up at the managers.&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/li&gt;&lt;li class=&quot;Z1qcYe&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAD&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;oSLmPe#HokZ0d&quot; jsuid=&quot;dRtJEb_1s&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px 0px 12px;&quot;&gt;&lt;span class=&quot;iNqyIf&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;KdQfFc#d5Qebf&quot; jsuid=&quot;dRtJEb_1t&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;rQesXe MPyX&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;tP2kf#s32ZS&quot; jsuid=&quot;dRtJEb_1u&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;&lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;dRtJEb_1v&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;ON e.manager_id = m.employee_id&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;: Establishes the relationship path between the employee and their boss.&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/li&gt;&lt;li class=&quot;Z1qcYe&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAE&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;oSLmPe#HokZ0d&quot; jsuid=&quot;dRtJEb_1w&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;iNqyIf&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;KdQfFc#d5Qebf&quot; jsuid=&quot;dRtJEb_1x&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;rQesXe MPyX&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;tP2kf#s32ZS&quot; jsuid=&quot;dRtJEb_1y&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;&lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;dRtJEb_1z&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;WHERE e.salary = m.salary&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;: Isolates the records where both parties make the exact same amount of money.&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/li&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/ul&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;dRtJEb_25|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;dRtJEb_25&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;hr class=&quot;s6NV4e&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-pl=&quot;|||[]&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;gWGJ0d#iOlsLd&quot; jsuid=&quot;dRtJEb_26&quot; style=&quot;border-bottom: 0px rgb(128, 128, 128); margin: 32px 0px;&quot; /&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;dRtJEb_27|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;dRtJEb_27&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=dRtJEb_28/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;dRtJEb_28&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;Complete Playground Script (Schema + Test Data)&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIExAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;dRtJEb_29&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;Copy and execute this script to test the logic live:&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;dRtJEb_2f|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;dRtJEb_2f&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;BpxUDf aiModeUiCodeBlock__Container&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIFBAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;dRtJEb_2i,dRtJEb_2h&quot; jsaction=&quot;&quot; jscontroller=&quot;Liu6s#lcO7sb&quot; jsuid=&quot;dRtJEb_2g&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 4px 0px 0px;&quot;&gt;&lt;div data-processed=&quot;true&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;rq1a2&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 0px;&quot;&gt;&lt;div class=&quot;a2TNg&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;GlO4G&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; margin: 0px;&quot;&gt;sql&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;PGvq2d&quot; dir=&quot;ltr&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;pre style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 14px 0px;&quot;&gt;&lt;code jsuid=&quot;dRtJEb_2i&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- 1. CREATE TABLE SCHEMA&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;CREATE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;TABLE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees (
    employee_id INT &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;PRIMARY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;KEY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;,
    employee_name VARCHAR(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
    salary &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;DECIMAL&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
    manager_id INT,
    &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;FOREIGN&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;KEY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; (manager_id) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;REFERENCES&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees(employee_id)
);

&lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- 2. INSERT SAMPLE DATA&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Top levels (No managers)&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;INSERT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;INTO&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees (employee_id, employee_name, salary, manager_id) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;VALUES&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Fiona Gallagher&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;120000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;), &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- CEO&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Alice Smith&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;95000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;);     &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- VP&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Reports&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;INSERT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;INTO&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees (employee_id, employee_name, salary, manager_id) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;VALUES&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Bob Jones&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;75000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),      &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Reports to Fiona (Diff Salary)&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Charlie Brown&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;95000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),  &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Reports to Alice (SAME Salary - Matches!)&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Diana Prince&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;95000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),   &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Reports to Alice (SAME Salary - Matches!)&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Evan Wright&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;60000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;);    &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Reports to Bob (Diff Salary)&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- 3. EXECUTE THE SELF-JOIN QUERY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; 
    e.employee_name &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employee_name,
    e.salary &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employee_salary,
    m.employee_name &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; manager_name
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees e
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;INNER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;JOIN&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees m &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;ON&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; e.manager_id = m.employee_id
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;WHERE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; e.salary = m.salary;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;iMHp6c&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 3px 0px 0px;&quot;&gt;&lt;div class=&quot;ZIumpf&quot; style=&quot;border-bottom: 0px rgb(32, 33, 36); font-size: 12px; margin: 0px;&quot;&gt;Use code with caution.&lt;/div&gt;&lt;span data-ved=&quot;2ahUKEwju6Ou379qXAxUIzTgGHeD0BMoQopQPegYIAAgUEAE&quot; jsaction=&quot;action:&amp;amp;dRtJEb_2g|ZUljYd&quot; jsuid=&quot;dRtJEb_2h&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwju6Ou379qXAxUIzTgGHeD0BMoQh9gSegYIAAgUEAI&quot; jsaction=&quot;&quot; jscontroller=&quot;cXTEid#e0nEwf&quot; jsuid=&quot;dRtJEb_2j&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd||GVEHxc=*Q0pj3b|[]--&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;!--TgQPHd|||[[&amp;quot;sql&amp;quot;,&amp;quot;-- 1. CREATE TABLE SCHEMA\nCREATE TABLE employees (\n    employee_id INT PRIMARY KEY,\n    employee_name VARCHAR(100),\n    salary DECIMAL(10, 2),\n    manager_id INT,\n    FOREIGN KEY (manager_id) REFERENCES employees(employee_id)\n);\n\n-- 2. INSERT SAMPLE DATA\n-- Top levels (No managers)\nINSERT INTO employees (employee_id, employee_name, salary, manager_id) VALUES\n(1, &amp;#39;Fiona Gallagher&amp;#39;, 120000.00, NULL), -- CEO\n(2, &amp;#39;Alice Smith&amp;#39;, 95000.00, NULL);     -- VP\n\n-- Reports\nINSERT INTO employees (employee_id, employee_name, salary, manager_id) VALUES\n(3, &amp;#39;Bob Jones&amp;#39;, 75000.00, 1),      -- Reports to Fiona (Diff Salary)\n(4, &amp;#39;Charlie Brown&amp;#39;, 95000.00, 2),  -- Reports to Alice (SAME Salary - Matches!)\n(5, &amp;#39;Diana Prince&amp;#39;, 95000.00, 2),   -- Reports to Alice (SAME Salary - Matches!)\n(6, &amp;#39;Evan Wright&amp;#39;, 60000.00, 3);    -- Reports to Bob (Diff Salary)\n\n-- 3. EXECUTE THE SELF-JOIN QUERY\nSELECT \n    e.employee_name AS employee_name,\n    e.salary AS employee_salary,\n    m.employee_name AS manager_name\nFROM employees e\nINNER JOIN employees m ON e.manager_id \u003d m.employee_id\nWHERE e.salary \u003d m.salary;\n&amp;quot;,[[&amp;quot;-- 1. CREATE TABLE SCHEMA&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;CREATE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;TABLE&amp;quot;,3],[&amp;quot; employees (\n    employee_id INT &amp;quot;,0],[&amp;quot;PRIMARY&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;KEY&amp;quot;,3],[&amp;quot;,\n    employee_name VARCHAR(&amp;quot;,0],[&amp;quot;100&amp;quot;,6],[&amp;quot;),\n    salary &amp;quot;,0],[&amp;quot;DECIMAL&amp;quot;,3],[&amp;quot;(&amp;quot;,0],[&amp;quot;10&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;2&amp;quot;,6],[&amp;quot;),\n    manager_id INT,\n    &amp;quot;,0],[&amp;quot;FOREIGN&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;KEY&amp;quot;,3],[&amp;quot; (manager_id) &amp;quot;,0],[&amp;quot;REFERENCES&amp;quot;,3],[&amp;quot; employees(employee_id)\n);\n\n&amp;quot;,0],[&amp;quot;-- 2. INSERT SAMPLE DATA&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;-- Top levels (No managers)&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;INSERT&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;INTO&amp;quot;,3],[&amp;quot; employees (employee_id, employee_name, salary, manager_id) &amp;quot;,0],[&amp;quot;VALUES&amp;quot;,3],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Fiona Gallagher&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;120000.00&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;NULL&amp;quot;,3],[&amp;quot;), &amp;quot;,0],[&amp;quot;-- CEO&amp;quot;,5],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;2&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Alice Smith&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;95000.00&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;NULL&amp;quot;,3],[&amp;quot;);     &amp;quot;,0],[&amp;quot;-- VP&amp;quot;,5],[&amp;quot;\n\n&amp;quot;,0],[&amp;quot;-- Reports&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;INSERT&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;INTO&amp;quot;,3],[&amp;quot; employees (employee_id, employee_name, salary, manager_id) &amp;quot;,0],[&amp;quot;VALUES&amp;quot;,3],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;3&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Bob Jones&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;75000.00&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot;),      &amp;quot;,0],[&amp;quot;-- Reports to Fiona (Diff Salary)&amp;quot;,5],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;4&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Charlie Brown&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;95000.00&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;2&amp;quot;,6],[&amp;quot;),  &amp;quot;,0],[&amp;quot;-- Reports to Alice (SAME Salary - Matches!)&amp;quot;,5],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;5&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Diana Prince&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;95000.00&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;2&amp;quot;,6],[&amp;quot;),   &amp;quot;,0],[&amp;quot;-- Reports to Alice (SAME Salary - Matches!)&amp;quot;,5],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;6&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Evan Wright&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;60000.00&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;3&amp;quot;,6],[&amp;quot;);    &amp;quot;,0],[&amp;quot;-- Reports to Bob (Diff Salary)&amp;quot;,5],[&amp;quot;\n\n&amp;quot;,0],[&amp;quot;-- 3. EXECUTE THE SELF-JOIN QUERY&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; \n    e.employee_name &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; employee_name,\n    e.salary &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; employee_salary,\n    m.employee_name &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; manager_name\n&amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; employees e\n&amp;quot;,0],[&amp;quot;INNER&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;JOIN&amp;quot;,3],[&amp;quot; employees m &amp;quot;,0],[&amp;quot;ON&amp;quot;,3],[&amp;quot; e.manager_id \u003d m.employee_id\n&amp;quot;,0],[&amp;quot;WHERE&amp;quot;,3],[&amp;quot; e.salary \u003d m.salary;\n&amp;quot;,0]]]]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;dRtJEb_2n|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;dRtJEb_2n&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=dRtJEb_2o/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;dRtJEb_2o&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;Expected Query Output&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;dRtJEb_2p|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;dRtJEb_2p&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;Fv6NCb&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIFhAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwju6Ou379qXAxUIzTgGHeD0BMoQ-q4QegYIAAgWEAA&quot; jsaction=&quot;rcuQ6b:&amp;amp;dRtJEb_2q|npT2md;scroll:&amp;amp;dRtJEb_2q|ZUljYd&quot; jscontroller=&quot;kbUand#UYOFMe&quot; jsuid=&quot;dRtJEb_2q&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 4px 0px 12px;&quot;&gt;&lt;table class=&quot;NRefec&quot; data-animation-nesting=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 14px; margin: 0px;&quot;&gt;&lt;tbody style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwju6Ou379qXAxUIzTgGHeD0BMoQw4oVegYIAAgWEAE&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;dRtJEb_2r&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;th class=&quot;BSFG4e&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;qmn2r#iLQbnd&quot; jsuid=&quot;dRtJEb_2s&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;employee_name&lt;!--TgQPHd|||[]--&gt;&lt;/th&gt;&lt;th class=&quot;BSFG4e&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;qmn2r#iLQbnd&quot; jsuid=&quot;dRtJEb_2t&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;employee_salary&lt;!--TgQPHd|||[]--&gt;&lt;/th&gt;&lt;th class=&quot;BSFG4e&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;qmn2r#iLQbnd&quot; jsuid=&quot;dRtJEb_2u&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;manager_name&lt;!--TgQPHd|||[]--&gt;&lt;/th&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwju6Ou379qXAxUIzTgGHeD0BMoQw4oVegYIAAgWEAI&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;dRtJEb_2v&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;dRtJEb_2w&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Charlie Brown&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;dRtJEb_2x&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;95000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;dRtJEb_2y&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Alice Smith&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwju6Ou379qXAxUIzTgGHeD0BMoQw4oVegYIAAgWEAM&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;dRtJEb_2z&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;dRtJEb_30&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;Diana Prince&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;dRtJEb_31&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;95000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;dRtJEb_32&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;Alice Smith&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;!--TgQPHd|||[[1,0,0,3,null,&amp;quot;&amp;quot;]]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;dRtJEb_33|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;dRtJEb_33&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;AHmQrc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIFxAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;LkYPVc#wdvZmf&quot; jsuid=&quot;dRtJEb_34&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIFxAB&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;dRtJEb_35&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;&lt;br /&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;dRtJEb_3d|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;dRtJEb_3d&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;dRtJEb_3f|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;dRtJEb_3f&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;dRtJEb_5s|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;dRtJEb_5s&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-subtree=&quot;aimba&quot; jsaction=&quot;&quot; jscontroller=&quot;v48bt#VKyOOd&quot; jsuid=&quot;dRtJEb_5t&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;SGF5Lb&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;mk5ZW#TASLyc&quot; jsuid=&quot;dRtJEb_8&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;SGF5Lb&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;mk5ZW#TASLyc&quot; jsuid=&quot;dRtJEb_9&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;SGF5Lb&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;mk5ZW#TASLyc&quot; jsuid=&quot;dRtJEb_a&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;zp3Dsd#fP0RJ&quot; jsuid=&quot;dRtJEb_b&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div data-processed=&quot;true&quot; data-xid=&quot;aQR2uf&quot; jsaction=&quot;aimRestoredThreadVisible:&amp;amp;dRtJEb_1|ZUljYd;requestToggleBottomSheet:&amp;amp;dRtJEb_1|aXD3Gb&quot; jsuid=&quot;dRtJEb_2&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;/div&gt;&lt;div data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;dRtJEb_h,dRtJEb_i&quot; jsaction=&quot;rcuQ6b:&amp;amp;dRtJEb_g|npT2md&quot; jscontroller=&quot;CAwPlc#Hx4Oqd&quot; jsuid=&quot;dRtJEb_g&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;!--TgQPHddRtJEb_1/VWapad;dRtJEb_1/YOIIaf|||[{&amp;quot;s&amp;quot;:false,&amp;quot;i&amp;quot;:&amp;quot;dRtJEb_1/YOIIaf&amp;quot;},{&amp;quot;s&amp;quot;:null,&amp;quot;i&amp;quot;:&amp;quot;dRtJEb_1/VWapad&amp;quot;},156,{&amp;quot;s&amp;quot;:null,&amp;quot;i&amp;quot;:&amp;quot;dRtJEb_1/C5DOxd&amp;quot;},[&amp;quot;AimExportActionToastLink&amp;quot;,309275],&amp;quot;\u0026dRtJEb_1:bREfu&amp;quot;,false]--&gt;&lt;/div&gt;&lt;!--TgQPHd|dRtJEb_1/C5DOxd;dRtJEb_1/VWapad;dRtJEb_1/LL5gb;dRtJEb_1/We76zc;dRtJEb_1/YOIIaf||[[null,0,null,0,null,0,[&amp;quot;Find employees who have the same salary as their manager.&amp;quot;],null,0,[&amp;quot;Find employees who have the same salary as their manager.&amp;quot;],0]]--&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/9198073852071720309/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/find-employees-who-have-same-salary-as.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/9198073852071720309'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/9198073852071720309'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/find-employees-who-have-same-salary-as.html' title='Find employees who have the same salary as their manager.'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-5989542988567311105</id><published>2026-11-02T19:30:00.000-08:00</published><updated>2026-11-02T19:30:00.128-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><title type='text'>How do you troubleshoot a production API issue in Azure?</title><content type='html'>&lt;h1&gt;Troubleshooting a Production API Issue in Azure&lt;/h1&gt;
&lt;p&gt;The goal is to &lt;strong&gt;stabilize first, diagnose second, fix third&lt;/strong&gt;. Work from the outside in: is it the platform, the network, your code, or a dependency?&lt;/p&gt;
&lt;h2&gt;1. Triage (first 5 minutes)&lt;/h2&gt;
&lt;p&gt;Establish the facts before touching anything:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;What is the symptom?&lt;/strong&gt; Errors (5xx/4xx), slowness, timeouts, or total outage?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scope:&lt;/strong&gt; all users or some? All endpoints or one? One region or instance, or everywhere?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;When did it start?&lt;/strong&gt; Line it up against deployments, config changes, certificate expiries, and traffic spikes. Most incidents trace back to a recent change.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Is it Azure?&lt;/strong&gt; Check &lt;strong&gt;Azure Service Health&lt;/strong&gt; and &lt;strong&gt;Resource Health&lt;/strong&gt; for your subscription and the specific resource. Platform incidents and maintenance show up here.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;If a recent deployment is the likely cause, roll back first and investigate later.&lt;/strong&gt; With deployment slots, swap back. That&#39;s the fastest mitigation you have.&lt;/p&gt;
&lt;h2&gt;2. Check the golden signals in Application Insights&lt;/h2&gt;
&lt;p&gt;Open &lt;strong&gt;Application Insights&lt;/strong&gt; and go through these in order:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Failures blade:&lt;/strong&gt; which operations and exception types are spiking, with sample failed requests.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Performance blade:&lt;/strong&gt; which operations got slower, and whether the time is in your code or in a dependency.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Application Map:&lt;/strong&gt; which node is red (slow or failing). This shows quickly whether the API or something it calls is at fault.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Live Metrics:&lt;/strong&gt; real-time view while you test or mitigate.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;End-to-end transaction details:&lt;/strong&gt; follow a single failed request through all services using its operation ID.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Useful KQL:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-kusto&quot;&gt;// Failure trend by result code
requests
| where timestamp &amp;gt; ago(2h)
| summarize total = count(), failed = countif(success == false) by bin(timestamp, 5m)
| extend failureRate = todouble(failed) / total
| render timechart

// Is it a dependency?
dependencies
| where timestamp &amp;gt; ago(2h) and success == false
| summarize count() by target, type, resultCode
| order by count_ desc

// Latency percentiles by operation
requests
| where timestamp &amp;gt; ago(2h)
| summarize p50 = percentile(duration, 50), p95 = percentile(duration, 95), count() by name
| order by p95 desc

// Top exceptions
exceptions
| where timestamp &amp;gt; ago(2h)
| summarize count() by type, outerMessage
| order by count_ desc
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Compare the bad period against the same time yesterday or last week to separate real regressions from normal patterns.&lt;/p&gt;
&lt;h2&gt;3. Narrow down by symptom&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symptom&lt;/th&gt;
&lt;th&gt;Likely causes&lt;/th&gt;
&lt;th&gt;Where to look&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;500s&lt;/strong&gt; after a deploy&lt;/td&gt;
&lt;td&gt;Bug, missing config, bad migration&lt;/td&gt;
&lt;td&gt;Exceptions, deployment history, diff of app settings&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;500s / timeouts, no deploy&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Failing dependency (SQL, Redis, downstream API), expired secret or cert&lt;/td&gt;
&lt;td&gt;Dependencies table, Application Map&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;401/403&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Expired token or secret, changed app role or RBAC, clock/audience mismatch, rotated key&lt;/td&gt;
&lt;td&gt;Entra sign-in logs, role assignments, Key Vault access logs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;429&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Throttling by a downstream service (Cosmos DB RU limits, Key Vault, Storage) or by APIM&lt;/td&gt;
&lt;td&gt;Response headers, service metrics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;502/503/504&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;App crashing or restarting, instances unhealthy, gateway timeout (App Gateway/Front Door ~230s limit on App Service)&lt;/td&gt;
&lt;td&gt;Health check status, restarts, Diagnose and solve problems&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Slow responses&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Slow SQL queries, cold starts, thread pool starvation, CPU/memory pressure, chatty calls&lt;/td&gt;
&lt;td&gt;Performance blade, dependency durations, App Service metrics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Intermittent failures&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;One bad instance, SNAT port exhaustion, transient faults without retries, DNS issues&lt;/td&gt;
&lt;td&gt;Per-instance breakdown (&lt;code&gt;cloud_RoleInstance&lt;/code&gt;), connection metrics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Works in one place, not another&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;NSG/firewall/private endpoint/DNS change&lt;/td&gt;
&lt;td&gt;Network diagnostics (below)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;4. Platform-level diagnostics&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;App Service / Functions:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Diagnose and solve problems&lt;/strong&gt; blade: guided detectors for HTTP 5xx, high CPU, memory, slow requests, SNAT exhaustion, and app crashes. Start here when the cause isn&#39;t obvious.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Metrics:&lt;/strong&gt; CPU, memory working set, requests, response time, HTTP 5xx, and instance count. Look for saturation or a scale-out that didn&#39;t happen.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Log stream&lt;/strong&gt; for live output: &lt;code&gt;az webapp log tail --name my-app --resource-group my-rg&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Kudu (SCM) console&lt;/strong&gt; for process explorer, environment variables, and crash dumps.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Health check:&lt;/strong&gt; verify the path is configured and which instances are being removed from rotation.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Containers / AKS / Container Apps:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;kubectl get pods&lt;/code&gt;, &lt;code&gt;kubectl describe pod&lt;/code&gt;, &lt;code&gt;kubectl logs --previous&lt;/code&gt; for restart loops (&lt;code&gt;CrashLoopBackOff&lt;/code&gt;, &lt;code&gt;OOMKilled&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Check readiness and liveness probes, resource limits, and node health.&lt;/li&gt;
&lt;li&gt;For Container Apps, use the &lt;strong&gt;Log stream&lt;/strong&gt; and &lt;code&gt;ContainerAppConsoleLogs&lt;/code&gt; / &lt;code&gt;ContainerAppSystemLogs&lt;/code&gt; tables.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;APIM / Front Door / Application Gateway (if in front):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Check whether failures originate at the gateway or the backend. Gateway logs show backend response codes, backend time vs. total time, and WAF blocks.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;WAF rule&lt;/strong&gt; or rate limit blocking legitimate traffic often looks like an app problem.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;5. Check dependencies&lt;/h2&gt;
&lt;p&gt;Most production API incidents originate in something the API calls:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Azure SQL:&lt;/strong&gt; Query Performance Insight, blocking and deadlocks, DTU/vCore saturation, connection limits, failover events. Check whether a new query plan or missing index is the cause.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cosmos DB:&lt;/strong&gt; 429s and RU consumption, hot partitions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Service Bus / Event Hubs:&lt;/strong&gt; growing queue depth, dead-letter counts, lock-expired errors, throttling.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Key Vault:&lt;/strong&gt; throttling, or access denied after a role or network change.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Redis:&lt;/strong&gt; memory pressure, evictions, connection limits.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Storage:&lt;/strong&gt; throttling and latency metrics.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Third-party APIs:&lt;/strong&gt; check their status pages and your outgoing call durations.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;6. Network and connectivity&lt;/h2&gt;
&lt;p&gt;If the app can&#39;t reach something or can&#39;t be reached:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Network Watcher:&lt;/strong&gt; &lt;em&gt;Connection troubleshoot&lt;/em&gt;, &lt;em&gt;IP flow verify&lt;/em&gt;, and &lt;em&gt;NSG flow logs&lt;/em&gt; show whether a rule is dropping traffic.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DNS:&lt;/strong&gt; private endpoints need correct private DNS zone links. From Kudu, run &lt;code&gt;nameresolver &amp;lt;host&amp;gt;&lt;/code&gt; and &lt;code&gt;tcpping &amp;lt;host:port&amp;gt;&lt;/code&gt; (on Windows App Service).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Firewall and access restrictions:&lt;/strong&gt; recent changes to storage, SQL, or Key Vault firewalls often cause sudden &lt;code&gt;403&lt;/code&gt;s or timeouts.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SNAT port exhaustion:&lt;/strong&gt; many outbound connections to the same endpoint can exhaust ports. Reuse &lt;code&gt;HttpClient&lt;/code&gt; through &lt;code&gt;IHttpClientFactory&lt;/code&gt;, use connection pooling, or add a NAT Gateway.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;TLS and certificates:&lt;/strong&gt; expired or rotated certificates cause sudden handshake failures.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;7. Compare against change history&lt;/h2&gt;
&lt;p&gt;Ask &quot;what changed?&quot; and verify it from records, not memory:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Activity Log:&lt;/strong&gt; shows control-plane changes (config updates, scaling, role assignments, deployments, key rotations). Filter by time window around the incident start.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Deployment history / CI-CD pipeline runs&lt;/strong&gt; and any app setting changes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Entra audit logs:&lt;/strong&gt; app registration, secret, or permission changes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Resource Graph or Change Analysis&lt;/strong&gt; (in Diagnose and solve problems) to see configuration diffs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;8. Go deeper when needed&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Memory or CPU issues:&lt;/strong&gt; capture a &lt;strong&gt;memory dump or profiler trace&lt;/strong&gt; through &lt;em&gt;Diagnose and solve problems&lt;/em&gt; (Collect Memory Dump, Profiler) or &lt;code&gt;dotnet-dump&lt;/code&gt;/&lt;code&gt;dotnet-trace&lt;/code&gt; in containers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Thread pool starvation&lt;/strong&gt; (common with sync-over-async): look for rising response times with low CPU, and check &lt;code&gt;ThreadPool&lt;/code&gt; metrics in Application Insights or &lt;code&gt;dotnet-counters&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reproduce in a lower environment&lt;/strong&gt; using the same request payload and the operation ID details from the failure.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Increase logging temporarily&lt;/strong&gt; for the affected component, then revert it. Sampling can hide rare failures, so check whether it&#39;s dropping the data you need.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;9. Mitigate while you investigate&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Roll back&lt;/strong&gt; or swap slots.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scale up/out&lt;/strong&gt; if it&#39;s resource saturation (buys time, doesn&#39;t fix the cause).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Restart&lt;/strong&gt; the app or a single bad instance as a last resort. Note the time and capture evidence first, because a restart destroys state.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Disable the faulty feature&lt;/strong&gt; with a feature flag, or route traffic away (Front Door / Traffic Manager) from an unhealthy region.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Add retries with backoff and circuit breakers&lt;/strong&gt; (Polly, or &lt;code&gt;Microsoft.Extensions.Http.Resilience&lt;/code&gt;) if a dependency is flaky.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Communicate:&lt;/strong&gt; post status updates early, even if the cause is unknown.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;10. Afterwards&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Write a &lt;strong&gt;blameless post-incident review&lt;/strong&gt;: timeline, root cause, detection gap, and action items.&lt;/li&gt;
&lt;li&gt;Add the &lt;strong&gt;missing alert&lt;/strong&gt; that would have caught it sooner (failure rate, p95 latency, dependency failures, queue depth, certificate and secret expiry).&lt;/li&gt;
&lt;li&gt;Add &lt;strong&gt;health checks, synthetic availability tests&lt;/strong&gt; (Standard tests), and &lt;strong&gt;dashboards&lt;/strong&gt; for the signals you had to hunt for.&lt;/li&gt;
&lt;li&gt;Make the fix safer to ship: &lt;strong&gt;deployment slots, canary releases, automated rollback&lt;/strong&gt;, and load testing for the failure mode.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Quick checklist:&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Check &lt;strong&gt;Service Health&lt;/strong&gt; and &lt;strong&gt;recent changes&lt;/strong&gt; (deploys, config, secrets, certs).&lt;/li&gt;
&lt;li&gt;Open &lt;strong&gt;Application Insights&lt;/strong&gt;: Failures, Performance, Application Map.&lt;/li&gt;
&lt;li&gt;Decide: &lt;strong&gt;my code, a dependency, or the platform/network?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Pull logs and traces for a &lt;strong&gt;single failing operation ID&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mitigate&lt;/strong&gt; (rollback, scale, failover) before the deep dive if users are affected.&lt;/li&gt;
&lt;li&gt;Confirm recovery from the metrics, then run the &lt;strong&gt;post-incident review&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/5989542988567311105/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/how-do-you-troubleshoot-production-api.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/5989542988567311105'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/5989542988567311105'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/how-do-you-troubleshoot-production-api.html' title='How do you troubleshoot a production API issue in Azure?'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-8715872951419290041</id><published>2026-11-02T19:30:00.000-08:00</published><updated>2026-11-02T19:30:00.128-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><title type='text'>How do you implement logging and monitoring using Application Insights?</title><content type='html'>&lt;h1&gt;Logging and Monitoring with Application Insights&lt;/h1&gt;
&lt;p&gt;Application Insights is the application performance monitoring (APM) feature of &lt;strong&gt;Azure Monitor&lt;/strong&gt;. It collects requests, dependencies (SQL, HTTP, Service Bus), exceptions, traces, custom metrics, and custom events, and gives you tools to query, visualize, and alert on them.&lt;/p&gt;
&lt;p&gt;Current Application Insights resources are &lt;strong&gt;workspace-based&lt;/strong&gt;: the data is stored in a &lt;strong&gt;Log Analytics workspace&lt;/strong&gt;, so you can query it alongside other Azure logs with KQL. Classic (non-workspace) resources are retired, so create new ones as workspace-based.&lt;/p&gt;
&lt;h2&gt;1. Create the resource&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az monitor log-analytics workspace create \
  --resource-group my-rg --workspace-name my-logs --location centralindia

az monitor app-insights component create \
  --app my-app-insights --resource-group my-rg --location centralindia \
  --workspace my-logs --kind web
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Get the connection string (use this, not the old instrumentation key alone):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az monitor app-insights component show --app my-app-insights \
  --resource-group my-rg --query connectionString -o tsv
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;2. Instrument a .NET app&lt;/h2&gt;
&lt;p&gt;There are two options. Microsoft&#39;s recommended path for new ASP.NET Core apps is the &lt;strong&gt;Azure Monitor OpenTelemetry Distro&lt;/strong&gt;, which replaces the older Application Insights SDK as the main approach. The classic SDK still works and is fine for existing apps.&lt;/p&gt;
&lt;h3&gt;Option A: Azure Monitor OpenTelemetry (recommended)&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Azure.Monitor.OpenTelemetry.AspNetCore
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Azure.Monitor.OpenTelemetry.AspNetCore;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenTelemetry().UseAzureMonitor();

var app = builder.Build();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Set the connection string via configuration (not in code):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=...;IngestionEndpoint=https://...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This automatically collects incoming requests, outgoing HTTP calls, SQL calls, exceptions, &lt;code&gt;ILogger&lt;/code&gt; output, and performance counters.&lt;/p&gt;
&lt;h3&gt;Option B: Classic Application Insights SDK&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Microsoft.ApplicationInsights.AspNetCore
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddApplicationInsightsTelemetry();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Again, provide &lt;code&gt;APPLICATIONINSIGHTS_CONNECTION_STRING&lt;/code&gt; through app settings or environment variables.&lt;/p&gt;
&lt;h3&gt;Azure Functions (isolated worker)&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Microsoft.Azure.Functions.Worker.ApplicationInsights
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services =&amp;gt;
    {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
    })
    .Build();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that the isolated worker applies a default logging filter that can hide &lt;code&gt;Information&lt;/code&gt; logs from your code. If your logs are missing, remove it in &lt;code&gt;ConfigureLogging&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;App Service with no code changes&lt;/h3&gt;
&lt;p&gt;For App Service, you can enable &lt;strong&gt;Application Insights&lt;/strong&gt; under the app&#39;s &lt;strong&gt;Monitoring&lt;/strong&gt; blade (auto-instrumentation, &quot;codeless&quot;). It&#39;s the quickest start, but code-based instrumentation gives you more control for custom telemetry.&lt;/p&gt;
&lt;h2&gt;3. Logging with &lt;code&gt;ILogger&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Use the standard .NET &lt;code&gt;ILogger&amp;lt;T&amp;gt;&lt;/code&gt;. Application Insights captures it automatically, and your structured properties become searchable custom dimensions.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class OrdersController : ControllerBase
{
    private readonly ILogger&amp;lt;OrdersController&amp;gt; _logger;

    public OrdersController(ILogger&amp;lt;OrdersController&amp;gt; logger) =&amp;gt; _logger = logger;

    [HttpPost]
    public IActionResult Create(Order order)
    {
        _logger.LogInformation(&quot;Creating order {OrderId} for customer {CustomerId}&quot;,
            order.Id, order.CustomerId);
        try
        {
            // ...
            return Ok();
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, &quot;Failed to create order {OrderId}&quot;, order.Id);
            throw;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Use message templates with named placeholders, not string interpolation. Templates keep the properties as structured fields you can filter on.&lt;/p&gt;
&lt;p&gt;Set log levels in &lt;code&gt;appsettings.json&lt;/code&gt;. Note the provider-specific section so you control what is sent to Application Insights:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;Logging&quot;: {
    &quot;LogLevel&quot;: { &quot;Default&quot;: &quot;Information&quot;, &quot;Microsoft.AspNetCore&quot;: &quot;Warning&quot; },
    &quot;ApplicationInsights&quot;: { &quot;LogLevel&quot;: { &quot;Default&quot;: &quot;Information&quot; } }
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;4. Custom telemetry&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Events and metrics&lt;/strong&gt; (with the OpenTelemetry distro, use &lt;code&gt;System.Diagnostics.Metrics&lt;/code&gt;; with the classic SDK, use &lt;code&gt;TelemetryClient&lt;/code&gt;):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// Custom metric with OpenTelemetry / .NET Meter
static readonly Meter Meter = new(&quot;MyApp.Orders&quot;);
static readonly Counter&amp;lt;long&amp;gt; OrdersCreated = Meter.CreateCounter&amp;lt;long&amp;gt;(&quot;orders_created&quot;);

OrdersCreated.Add(1, new KeyValuePair&amp;lt;string, object?&amp;gt;(&quot;region&quot;, &quot;EU&quot;));
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Register the meter so it&#39;s exported:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddOpenTelemetry()
    .UseAzureMonitor()
    .WithMetrics(m =&amp;gt; m.AddMeter(&quot;MyApp.Orders&quot;));
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// Classic SDK
_telemetryClient.TrackEvent(&quot;OrderPlaced&quot;,
    new Dictionary&amp;lt;string, string&amp;gt; { [&quot;region&quot;] = &quot;EU&quot; });
_telemetryClient.GetMetric(&quot;OrderValue&quot;).TrackValue(order.Total);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Custom spans&lt;/strong&gt; (distributed tracing) with &lt;code&gt;ActivitySource&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;static readonly ActivitySource Source = new(&quot;MyApp.Orders&quot;);

using var activity = Source.StartActivity(&quot;ProcessPayment&quot;);
activity?.SetTag(&quot;order.id&quot;, order.Id);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Register it with &lt;code&gt;.WithTracing(t =&amp;gt; t.AddSource(&quot;MyApp.Orders&quot;))&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;5. Distributed tracing across services&lt;/h2&gt;
&lt;p&gt;Application Insights correlates calls across services using the W3C &lt;code&gt;traceparent&lt;/code&gt; header. Requests, dependencies, logs, and exceptions that belong to one operation share an &lt;strong&gt;operation ID&lt;/strong&gt;, so you can follow a single user action across APIs, queues, and functions. Use &lt;strong&gt;Application Map&lt;/strong&gt; and the &lt;strong&gt;End-to-end transaction details&lt;/strong&gt; view to see this visually. Service Bus and HTTP calls propagate context automatically with the standard Azure SDKs.&lt;/p&gt;
&lt;p&gt;Set a meaningful &lt;strong&gt;cloud role name&lt;/strong&gt; so each service appears as its own node on the map:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddOpenTelemetry()
    .ConfigureResource(r =&amp;gt; r.AddService(&quot;orders-api&quot;))
    .UseAzureMonitor();
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;6. Querying with KQL&lt;/h2&gt;
&lt;p&gt;In &lt;strong&gt;Application Insights → Logs&lt;/strong&gt; (or the Log Analytics workspace):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-kusto&quot;&gt;// Failed requests in the last hour
requests
| where timestamp &amp;gt; ago(1h) and success == false
| summarize count() by resultCode, name
| order by count_ catch desc
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Correction: &lt;code&gt;catch&lt;/code&gt; isn&#39;t valid KQL there. The correct form is:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-kusto&quot;&gt;requests
| where timestamp &amp;gt; ago(1h) and success == false
| summarize failures = count() by resultCode, name
| order by failures desc
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-kusto&quot;&gt;// Slowest operations (p95)
requests
| where timestamp &amp;gt; ago(24h)
| summarize p95 = percentile(duration, 95) by name
| order by p95 desc

// Exceptions with context
exceptions
| where timestamp &amp;gt; ago(24h)
| project timestamp, type, outerMessage, operation_Id, cloud_RoleName

// All telemetry for one operation
union requests, dependencies, traces, exceptions
| where operation_Id == &quot;&amp;lt;id&amp;gt;&quot;
| order by timestamp asc

// Slow or failing dependencies (SQL, HTTP, Service Bus)
dependencies
| where timestamp &amp;gt; ago(24h) and success == false
| summarize count() by target, type
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note: in a workspace-based resource queried from the &lt;strong&gt;Log Analytics workspace&lt;/strong&gt;, the table names are &lt;code&gt;AppRequests&lt;/code&gt;, &lt;code&gt;AppDependencies&lt;/code&gt;, &lt;code&gt;AppExceptions&lt;/code&gt;, &lt;code&gt;AppTraces&lt;/code&gt;, and so on, with different column names (&lt;code&gt;TimeGenerated&lt;/code&gt;, &lt;code&gt;DurationMs&lt;/code&gt;). Queries from the Application Insights &lt;strong&gt;Logs&lt;/strong&gt; blade use the classic names shown above.&lt;/p&gt;
&lt;h2&gt;7. Monitoring features worth using&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Live Metrics:&lt;/strong&gt; near-real-time view of requests, failures, and CPU while you deploy or debug.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Application Map:&lt;/strong&gt; dependency graph with failure and latency per link.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Failures and Performance blades:&lt;/strong&gt; group exceptions and slow operations, then drill into samples.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Availability tests:&lt;/strong&gt; synthetic checks from multiple regions (URL ping is being replaced by &lt;strong&gt;Standard tests&lt;/strong&gt;; use those).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Smart detection:&lt;/strong&gt; automatic anomaly alerts for failure-rate and latency changes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Workbooks and dashboards:&lt;/strong&gt; shared visual reports built from KQL.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Profiler and Snapshot Debugger:&lt;/strong&gt; deeper diagnostics for slow code and exceptions (primarily classic SDK and App Service scenarios).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;8. Alerts&lt;/h2&gt;
&lt;p&gt;Create alert rules on metrics or on KQL queries, and route them to an &lt;strong&gt;action group&lt;/strong&gt; (email, SMS, Teams, webhook, Logic App).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az monitor metrics alert create \
  --name high-failed-requests --resource-group my-rg \
  --scopes &amp;lt;app-insights-resource-id&amp;gt; \
  --condition &quot;count requests/failed &amp;gt; 10&quot; \
  --window-size 5m --evaluation-frequency 1m \
  --action &amp;lt;action-group-id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Typical alerts: failed request spike, p95 latency above a threshold, exceptions rate, availability test failures, and dependency failures. Prefer &lt;strong&gt;log-based alerts&lt;/strong&gt; for business conditions (e.g., no orders in 30 minutes).&lt;/p&gt;
&lt;h2&gt;9. Cost and data control&lt;/h2&gt;
&lt;p&gt;Application Insights is billed by &lt;strong&gt;data ingested&lt;/strong&gt; (GB) to the workspace, so control volume deliberately:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Sampling:&lt;/strong&gt; adaptive sampling is on by default in the classic SDK. With OpenTelemetry, set &lt;code&gt;SamplingRatio&lt;/code&gt; (or use rate-limited sampling) in &lt;code&gt;AzureMonitorOptions&lt;/code&gt;. Sampled telemetry keeps correlated items together.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Log levels:&lt;/strong&gt; don&#39;t send &lt;code&gt;Debug&lt;/code&gt; or &lt;code&gt;Trace&lt;/code&gt; in production, and raise noisy framework categories to &lt;code&gt;Warning&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Daily cap:&lt;/strong&gt; set a cap on the workspace as a safety net, knowing that data stops being collected when it&#39;s hit.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Retention:&lt;/strong&gt; default is 90 days for Application Insights tables (30 days for Log Analytics generally); extend or archive only what you need.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Filter noise:&lt;/strong&gt; drop health-check requests and static files with a processor or filter.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;10. Security and good practice&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Never log secrets or PII&lt;/strong&gt; (tokens, passwords, card numbers, full emails). Sanitize or omit them before logging.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use Entra authentication for ingestion&lt;/strong&gt; (&lt;code&gt;DefaultAzureCredential&lt;/code&gt; with the &lt;em&gt;Monitoring Metrics Publisher&lt;/em&gt; role) and disable local (key-based) auth, so a leaked connection string can&#39;t be used to inject fake telemetry.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use RBAC&lt;/strong&gt; to control who can read logs (&lt;em&gt;Log Analytics Reader&lt;/em&gt;, &lt;em&gt;Monitoring Reader&lt;/em&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use private link&lt;/strong&gt; (Azure Monitor Private Link Scope) if telemetry must stay off the public internet.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use consistent correlation:&lt;/strong&gt; include IDs such as &lt;code&gt;OrderId&lt;/code&gt; in log templates so you can search by business key.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;One resource per environment&lt;/strong&gt; (or at least distinct cloud role names and an environment dimension) so dev noise doesn&#39;t pollute production.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Enabling Entra ingestion with the OpenTelemetry distro:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddOpenTelemetry().UseAzureMonitor(o =&amp;gt;
{
    o.Credential = new DefaultAzureCredential();
});
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Minimal setup checklist&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Create a workspace-based Application Insights resource.&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;Azure.Monitor.OpenTelemetry.AspNetCore&lt;/code&gt; and call &lt;code&gt;UseAzureMonitor()&lt;/code&gt;, with the connection string in app settings.&lt;/li&gt;
&lt;li&gt;Log through &lt;code&gt;ILogger&lt;/code&gt; with structured templates.&lt;/li&gt;
&lt;li&gt;Set the service name so Application Map shows each service.&lt;/li&gt;
&lt;li&gt;Add alerts for failures, latency, and availability.&lt;/li&gt;
&lt;li&gt;Configure sampling, log levels, and a daily cap to control cost.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/8715872951419290041/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/how-do-you-implement-logging-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/8715872951419290041'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/8715872951419290041'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/how-do-you-implement-logging-and.html' title='How do you implement logging and monitoring using Application Insights?'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-2006073861422640611</id><published>2026-11-01T19:30:00.000-08:00</published><updated>2026-11-01T19:30:00.118-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><title type='text'>How do you implement authentication using Entra ID, OAuth, and JWT? </title><content type='html'>&lt;h1&gt;Authentication with Entra ID, OAuth 2.0, and JWT&lt;/h1&gt;
&lt;p&gt;These three pieces fit together as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Microsoft Entra ID&lt;/strong&gt; is the identity provider (IdP). It authenticates users and apps and issues tokens.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;OAuth 2.0&lt;/strong&gt; is the authorization framework: how a client gets permission to call an API on behalf of a user or as itself.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;OpenID Connect (OIDC)&lt;/strong&gt; is a layer on OAuth 2.0 for sign-in. It adds an &lt;strong&gt;ID token&lt;/strong&gt; that tells your app who the user is.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JWT&lt;/strong&gt; is the token format. Entra issues access tokens and ID tokens as signed JSON Web Tokens.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Access tokens&lt;/strong&gt; are for APIs (&quot;this caller may do X&quot;). &lt;strong&gt;ID tokens&lt;/strong&gt; are for the client app (&quot;this user signed in&quot;). Never send an ID token to an API.&lt;/p&gt;
&lt;h2&gt;1. Choose the flow&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Flow&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;SPA or mobile app, user signs in, calls your API&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Authorization code + PKCE&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Server-side web app with user sign-in&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Authorization code&lt;/strong&gt; (with a client secret or certificate)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Service-to-service, no user (daemon, background job)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Client credentials&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;API calls another API as the signed-in user&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;On-behalf-of (OBO)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Avoid the implicit flow and the password (ROPC) flow. Both are legacy and discouraged.&lt;/p&gt;
&lt;h2&gt;2. Register the apps in Entra ID&lt;/h2&gt;
&lt;p&gt;You typically register two apps: one for the &lt;strong&gt;API&lt;/strong&gt; and one for the &lt;strong&gt;client&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;API registration:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Go to &lt;strong&gt;Entra ID → App registrations → New registration&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;Expose an API&lt;/strong&gt;, set the Application ID URI (e.g. &lt;code&gt;api://&amp;lt;api-client-id&amp;gt;&lt;/code&gt;) and add a scope such as &lt;code&gt;access_as_user&lt;/code&gt; for delegated (user) permissions.&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;App roles&lt;/strong&gt;, add roles such as &lt;code&gt;Orders.Read&lt;/code&gt; for app-only callers (and for user roles).&lt;/li&gt;
&lt;li&gt;In the manifest, make sure &lt;code&gt;requestedAccessTokenVersion&lt;/code&gt; is &lt;code&gt;2&lt;/code&gt; so you get v2.0 tokens.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Client registration:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Add a redirect URI. Use the &lt;strong&gt;SPA&lt;/strong&gt; platform for SPAs, which enables PKCE, or &lt;strong&gt;Web&lt;/strong&gt; for server apps.&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;API permissions&lt;/strong&gt;, add your API&#39;s scope or role and grant admin consent if needed.&lt;/li&gt;
&lt;li&gt;For confidential clients, add a &lt;strong&gt;certificate&lt;/strong&gt; (preferred) or client secret under &lt;em&gt;Certificates &amp;amp; secrets&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;3. Protect an ASP.NET Core API (validate JWTs)&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Microsoft.Identity.Web
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;appsettings.json&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;AzureAd&quot;: {
    &quot;Instance&quot;: &quot;https://login.microsoftonline.com/&quot;,
    &quot;TenantId&quot;: &quot;&amp;lt;tenant-id&amp;gt;&quot;,
    &quot;ClientId&quot;: &quot;&amp;lt;api-client-id&amp;gt;&quot;,
    &quot;Audience&quot;: &quot;api://&amp;lt;api-client-id&amp;gt;&quot;
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;Program.cs&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Microsoft.Identity.Web;

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApi(builder.Configuration.GetSection(&quot;AzureAd&quot;));

builder.Services.AddAuthorization(options =&amp;gt;
{
    options.AddPolicy(&quot;OrdersRead&quot;, p =&amp;gt; p.RequireRole(&quot;Orders.Read&quot;));
});

var app = builder.Build();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();
app.Run();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Controller:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;[Authorize]
[ApiController]
[Route(&quot;api/orders&quot;)]
public class OrdersController : ControllerBase
{
    // Delegated (user) token: check the scope claim
    [HttpGet]
    [RequiredScope(&quot;access_as_user&quot;)]
    public IActionResult GetMine() =&amp;gt; Ok(new { user = User.Identity?.Name });

    // App-only token (client credentials): check the roles claim
    [HttpGet(&quot;all&quot;)]
    [Authorize(Policy = &quot;OrdersRead&quot;)]
    public IActionResult GetAll() =&amp;gt; Ok();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;User tokens carry &lt;strong&gt;scopes&lt;/strong&gt; in the &lt;code&gt;scp&lt;/code&gt; claim, and app-only tokens carry &lt;strong&gt;app roles&lt;/strong&gt; in the &lt;code&gt;roles&lt;/code&gt; claim. Check the right one for the flow you expect.&lt;/p&gt;
&lt;h2&gt;4. Sign users in to a web app (OIDC)&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services
    .AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApp(builder.Configuration.GetSection(&quot;AzureAd&quot;))
    .EnableTokenAcquisitionToCallDownstreamApi(new[] { &quot;api://&amp;lt;api-client-id&amp;gt;/access_as_user&quot; })
    .AddInMemoryTokenCaches();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Inject &lt;code&gt;ITokenAcquisition&lt;/code&gt; to get an access token for the signed-in user and call your API:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var token = await _tokenAcquisition.GetAccessTokenForUserAsync(
    new[] { &quot;api://&amp;lt;api-client-id&amp;gt;/access_as_user&quot; });

_http.DefaultRequestHeaders.Authorization =
    new AuthenticationHeaderValue(&quot;Bearer&quot;, token);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For a &lt;strong&gt;SPA&lt;/strong&gt;, use &lt;strong&gt;MSAL.js&lt;/strong&gt; (&lt;code&gt;@azure/msal-browser&lt;/code&gt;, or &lt;code&gt;@azure/msal-react&lt;/code&gt; / &lt;code&gt;@azure/msal-angular&lt;/code&gt;). It handles the code + PKCE flow, token caching, and silent refresh:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;const msal = new PublicClientApplication({
  auth: { clientId: &quot;&amp;lt;spa-client-id&amp;gt;&quot;, authority: &quot;https://login.microsoftonline.com/&amp;lt;tenant-id&amp;gt;&quot; }
});

const result = await msal.acquireTokenPopup({
  scopes: [&quot;api://&amp;lt;api-client-id&amp;gt;/access_as_user&quot;]
});

fetch(&quot;https://my-api/api/orders&quot;, {
  headers: { Authorization: `Bearer ${result.accessToken}` }
});
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;5. Service-to-service (client credentials)&lt;/h2&gt;
&lt;p&gt;When there&#39;s no user, the caller authenticates as itself. Always request the &lt;code&gt;.default&lt;/code&gt; scope, which returns the app roles granted to that client:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var credential = new DefaultAzureCredential(); // managed identity in Azure

var token = await credential.GetTokenAsync(
    new TokenRequestContext(new[] { &quot;api://&amp;lt;api-client-id&amp;gt;/.default&quot; }));
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Prefer a &lt;strong&gt;managed identity&lt;/strong&gt; over a client secret. Assign the API&#39;s app role to the managed identity&#39;s service principal (via Graph, PowerShell, or Azure CLI). Outside Azure, use &lt;code&gt;ConfidentialClientApplication&lt;/code&gt; from &lt;code&gt;Microsoft.Identity.Client&lt;/code&gt; with a certificate.&lt;/p&gt;
&lt;h2&gt;6. What your API must validate in a JWT&lt;/h2&gt;
&lt;p&gt;A JWT has three base64url parts, &lt;code&gt;header.payload.signature&lt;/code&gt;. &lt;code&gt;AddMicrosoftIdentityWebApi&lt;/code&gt; does the following for you, but you should know what&#39;s being checked:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Signature:&lt;/strong&gt; verified using Entra&#39;s public signing keys, fetched from the OIDC metadata endpoint (&lt;code&gt;.../.well-known/openid-configuration&lt;/code&gt; → &lt;code&gt;jwks_uri&lt;/code&gt;) and cached and rotated automatically.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;iss&lt;/code&gt; (issuer):&lt;/strong&gt; must be your tenant, e.g. &lt;code&gt;https://login.microsoftonline.com/&amp;lt;tenant-id&amp;gt;/v2.0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;aud&lt;/code&gt; (audience):&lt;/strong&gt; must be your API (its client ID or Application ID URI). A token meant for another API must be rejected.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;exp&lt;/code&gt; / &lt;code&gt;nbf&lt;/code&gt;:&lt;/strong&gt; token is within its validity window (access tokens last roughly 60 to 90 minutes).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;scp&lt;/code&gt; or &lt;code&gt;roles&lt;/code&gt;:&lt;/strong&gt; the caller has the permission required for this operation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;tid&lt;/code&gt;:&lt;/strong&gt; for multi-tenant APIs, check that the tenant is one you allow.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Key claims you&#39;ll use: &lt;code&gt;oid&lt;/code&gt; (user or service principal object ID), &lt;code&gt;sub&lt;/code&gt;, &lt;code&gt;tid&lt;/code&gt;, &lt;code&gt;scp&lt;/code&gt;, &lt;code&gt;roles&lt;/code&gt;, &lt;code&gt;preferred_username&lt;/code&gt;, &lt;code&gt;appid&lt;/code&gt;/&lt;code&gt;azp&lt;/code&gt; (the calling client).&lt;/p&gt;
&lt;p&gt;If you ever need manual configuration without Microsoft.Identity.Web:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;.AddJwtBearer(o =&amp;gt;
{
    o.Authority = &quot;https://login.microsoftonline.com/&amp;lt;tenant-id&amp;gt;/v2.0&quot;;
    o.TokenValidationParameters = new()
    {
        ValidAudience = &quot;api://&amp;lt;api-client-id&amp;gt;&quot;,
        ValidateIssuer = true,
        ValidateAudience = true,
        ValidateLifetime = true
    };
});
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;7. Common pitfalls&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Mixing up token types:&lt;/strong&gt; APIs accept access tokens only, never ID tokens.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Wrong audience or token version:&lt;/strong&gt; a v1 token has a different &lt;code&gt;iss&lt;/code&gt; and &lt;code&gt;aud&lt;/code&gt; format than v2, so set the API&#39;s accepted token version to match your validation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Checking only authentication:&lt;/strong&gt; a valid token isn&#39;t enough. Always check scopes or roles, otherwise any app in your tenant that can get a token for your API is authorized.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Storing tokens in &lt;code&gt;localStorage&lt;/code&gt;:&lt;/strong&gt; this exposes them to XSS. Let MSAL manage caching, or use a backend-for-frontend (BFF) with HttpOnly cookies.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Client secrets in code or SPAs:&lt;/strong&gt; public clients (SPAs, mobile) can&#39;t keep secrets, which is why they use PKCE.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Decoding without validating:&lt;/strong&gt; reading claims from a JWT without verifying its signature proves nothing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Forgetting admin consent&lt;/strong&gt; for application permissions, which causes 403s.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rolling your own JWT handling:&lt;/strong&gt; use MSAL and Microsoft.Identity.Web rather than hand-parsing tokens and keys.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;8. Alternative: let Azure handle it (Easy Auth)&lt;/h2&gt;
&lt;p&gt;On App Service or Azure Functions, &lt;strong&gt;built-in authentication&lt;/strong&gt; validates the token before your code runs and passes claims to your app via headers (&lt;code&gt;X-MS-CLIENT-PRINCIPAL&lt;/code&gt;). It&#39;s the least-code option, though you get less control over fine-grained authorization than with middleware in your own code.&lt;/p&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Register an API (with scopes and app roles) and a client in Entra ID.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;auth code + PKCE&lt;/strong&gt; for users and &lt;strong&gt;client credentials&lt;/strong&gt; (ideally with a managed identity) for services.&lt;/li&gt;
&lt;li&gt;The client acquires an access token via MSAL and sends it as &lt;code&gt;Authorization: Bearer &amp;lt;token&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The API validates the JWT (signature, issuer, audience, expiry) and enforces &lt;strong&gt;scopes/roles&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/2006073861422640611/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/how-do-you-implement-authentication.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/2006073861422640611'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/2006073861422640611'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/how-do-you-implement-authentication.html' title='How do you implement authentication using Entra ID, OAuth, and JWT? '/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-2704674583668641563</id><published>2026-11-01T19:30:00.000-08:00</published><updated>2026-11-01T19:30:00.118-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Write a query to find employees with salary greater than average salary in the entire company, ordered by salary descending.</title><content type='html'>&lt;div class=&quot;pWvJNd&quot; data-complete=&quot;true&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;zp3Dsd#fP0RJ&quot; jsuid=&quot;InOZJd_5&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;div data-complete=&quot;true&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;z34MU#CsVNRe&quot; jsname=&quot;s7e4Od&quot; jsuid=&quot;InOZJd_6&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;mZJni&quot; data-container-id=&quot;main-col&quot; data-ctx-provider=&quot;[[[&amp;quot;dMtGDc&amp;quot;,&amp;quot;[false]&amp;quot;]]]&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwjCpdj87dqXAxWd1TgGHQMCIn4Q3KYQegYIAAgIEAE&quot; data-xid=&quot;VpUvz&quot; dir=&quot;ltr&quot; jsaction=&quot;cC6SSe:&amp;amp;InOZJd_7|mNzCb;&quot; jscontroller=&quot;Aoijq#INwBm&quot; jsname=&quot;KFl8ub&quot; jsuid=&quot;InOZJd_7&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAICxAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;InOZJd_o&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;&lt;span data-processed=&quot;true&quot; data-subtree=&quot;aimfl&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;To find employees whose salary is greater than the company-wide average, you cannot simply place &lt;/span&gt;&lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;InOZJd_q&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;WHERE salary &amp;gt; AVG(salary)&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; in a standard query because aggregate functions are not allowed in the &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;InOZJd_r&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;WHERE&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; clause without grouping.&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIDBAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;InOZJd_x&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;Instead, you must use a &lt;span class=&quot;rQesXe MPyX&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;tP2kf#s32ZS&quot; jsuid=&quot;InOZJd_y&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;Subquery&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt; or a &lt;span class=&quot;rQesXe MPyX&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;tP2kf#s32ZS&quot; jsuid=&quot;InOZJd_z&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;Window Function&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;.&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIDRAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;InOZJd_15&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;Here are the two best ways to write this query, followed by a complete playground script.&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_1b|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;InOZJd_1b&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;hr class=&quot;s6NV4e&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-pl=&quot;|||[]&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;gWGJ0d#iOlsLd&quot; jsuid=&quot;InOZJd_1c&quot; style=&quot;border-bottom: 0px rgb(128, 128, 128); margin: 32px 0px;&quot; /&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_1d|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;InOZJd_1d&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=InOZJd_1e/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;InOZJd_1e&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;Method 1: Using a Subquery (Standard &amp;amp; Highly Compatible)&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;InOZJd_1f&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;This method calculates the company-wide average first in an isolated subquery, then uses that single numeric value to filter the main table.&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_1l|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;InOZJd_1l&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;BpxUDf aiModeUiCodeBlock__Container&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIERAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;InOZJd_1o,InOZJd_1n&quot; jsaction=&quot;&quot; jscontroller=&quot;Liu6s#lcO7sb&quot; jsuid=&quot;InOZJd_1m&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 4px 0px 0px;&quot;&gt;&lt;div data-processed=&quot;true&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;rq1a2&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 0px;&quot;&gt;&lt;div class=&quot;a2TNg&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;GlO4G&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; margin: 0px;&quot;&gt;sql&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;PGvq2d&quot; dir=&quot;ltr&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;pre style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 14px 0px;&quot;&gt;&lt;code jsuid=&quot;InOZJd_1o&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; 
    employee_id,
    employee_name,
    department,
    salary
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;WHERE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; salary &amp;gt; (&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; AVG(salary) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees)
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;ORDER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;BY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; salary &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;DESC&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;iMHp6c&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 3px 0px 0px;&quot;&gt;&lt;div class=&quot;ZIumpf&quot; style=&quot;border-bottom: 0px rgb(32, 33, 36); font-size: 12px; margin: 0px;&quot;&gt;Use code with caution.&lt;/div&gt;&lt;span data-ved=&quot;2ahUKEwjCpdj87dqXAxWd1TgGHQMCIn4QopQPegYIAAgREAE&quot; jsaction=&quot;action:&amp;amp;InOZJd_1m|ZUljYd&quot; jsuid=&quot;InOZJd_1n&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwjCpdj87dqXAxWd1TgGHQMCIn4Qh9gSegYIAAgREAI&quot; jsaction=&quot;&quot; jscontroller=&quot;cXTEid#e0nEwf&quot; jsuid=&quot;InOZJd_1p&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd||GVEHxc=*Q0pj3b|[]--&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;!--TgQPHd|||[[&amp;quot;sql&amp;quot;,&amp;quot;SELECT \n    employee_id,\n    employee_name,\n    department,\n    salary\nFROM employees\nWHERE salary \u003e (SELECT AVG(salary) FROM employees)\nORDER BY salary DESC;\n&amp;quot;,[[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; \n    employee_id,\n    employee_name,\n    department,\n    salary\n&amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; employees\n&amp;quot;,0],[&amp;quot;WHERE&amp;quot;,3],[&amp;quot; salary \u003e (&amp;quot;,0],[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; AVG(salary) &amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; employees)\n&amp;quot;,0],[&amp;quot;ORDER&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;BY&amp;quot;,3],[&amp;quot; salary &amp;quot;,0],[&amp;quot;DESC&amp;quot;,3],[&amp;quot;;\n&amp;quot;,0]]]]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_1t|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;InOZJd_1t&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=InOZJd_1u/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;InOZJd_1u&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;Method 2: Using a Common Table Expression (CTE) &amp;amp; Window Function&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIExAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;InOZJd_1v&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;This approach calculates the average alongside your other data columns using &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;InOZJd_1w&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;AVG() OVER()&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;, allowing you to see exactly how much each employee exceeds the average.&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_22|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;InOZJd_22&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;BpxUDf aiModeUiCodeBlock__Container&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIFBAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;InOZJd_25,InOZJd_24&quot; jsaction=&quot;&quot; jscontroller=&quot;Liu6s#lcO7sb&quot; jsuid=&quot;InOZJd_23&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 4px 0px 0px;&quot;&gt;&lt;div data-processed=&quot;true&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;rq1a2&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 0px;&quot;&gt;&lt;div class=&quot;a2TNg&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;GlO4G&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; margin: 0px;&quot;&gt;sql&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;PGvq2d&quot; dir=&quot;ltr&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;pre style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 14px 0px;&quot;&gt;&lt;code jsuid=&quot;InOZJd_25&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;WITH&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; SalaryAnalysis &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; (
    &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; 
        employee_id,
        employee_name,
        department,
        salary,
        AVG(salary) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;OVER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;() &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; company_average
    &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees
)
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; 
    employee_id,
    employee_name,
    department,
    salary,
    ROUND(company_average, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; company_average
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; SalaryAnalysis
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;WHERE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; salary &amp;gt; company_average
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;ORDER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;BY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; salary &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;DESC&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;iMHp6c&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 3px 0px 0px;&quot;&gt;&lt;div class=&quot;ZIumpf&quot; style=&quot;border-bottom: 0px rgb(32, 33, 36); font-size: 12px; margin: 0px;&quot;&gt;Use code with caution.&lt;/div&gt;&lt;span data-ved=&quot;2ahUKEwjCpdj87dqXAxWd1TgGHQMCIn4QopQPegYIAAgUEAE&quot; jsaction=&quot;action:&amp;amp;InOZJd_23|ZUljYd&quot; jsuid=&quot;InOZJd_24&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwjCpdj87dqXAxWd1TgGHQMCIn4Qh9gSegYIAAgUEAI&quot; jsaction=&quot;&quot; jscontroller=&quot;cXTEid#e0nEwf&quot; jsuid=&quot;InOZJd_26&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd||GVEHxc=*Q0pj3b|[]--&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;!--TgQPHd|||[[&amp;quot;sql&amp;quot;,&amp;quot;WITH SalaryAnalysis AS (\n    SELECT \n        employee_id,\n        employee_name,\n        department,\n        salary,\n        AVG(salary) OVER() AS company_average\n    FROM employees\n)\nSELECT \n    employee_id,\n    employee_name,\n    department,\n    salary,\n    ROUND(company_average, 2) AS company_average\nFROM SalaryAnalysis\nWHERE salary \u003e company_average\nORDER BY salary DESC;\n&amp;quot;,[[&amp;quot;WITH&amp;quot;,3],[&amp;quot; SalaryAnalysis &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; (\n    &amp;quot;,0],[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; \n        employee_id,\n        employee_name,\n        department,\n        salary,\n        AVG(salary) &amp;quot;,0],[&amp;quot;OVER&amp;quot;,3],[&amp;quot;() &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; company_average\n    &amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; employees\n)\n&amp;quot;,0],[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; \n    employee_id,\n    employee_name,\n    department,\n    salary,\n    ROUND(company_average, &amp;quot;,0],[&amp;quot;2&amp;quot;,6],[&amp;quot;) &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; company_average\n&amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; SalaryAnalysis\n&amp;quot;,0],[&amp;quot;WHERE&amp;quot;,3],[&amp;quot; salary \u003e company_average\n&amp;quot;,0],[&amp;quot;ORDER&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;BY&amp;quot;,3],[&amp;quot; salary &amp;quot;,0],[&amp;quot;DESC&amp;quot;,3],[&amp;quot;;\n&amp;quot;,0]]]]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_2a|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;InOZJd_2a&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;hr class=&quot;s6NV4e&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-pl=&quot;|||[]&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;gWGJ0d#iOlsLd&quot; jsuid=&quot;InOZJd_2b&quot; style=&quot;border-bottom: 0px rgb(128, 128, 128); margin: 32px 0px;&quot; /&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_2c|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;InOZJd_2c&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=InOZJd_2d/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;InOZJd_2d&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;Complete Playground Script (Schema + Test Data)&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIFxAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;InOZJd_2e&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;Copy and execute this script to test the logic:&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_2k|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;InOZJd_2k&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;BpxUDf aiModeUiCodeBlock__Container&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIGBAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;InOZJd_2n,InOZJd_2m&quot; jsaction=&quot;&quot; jscontroller=&quot;Liu6s#lcO7sb&quot; jsuid=&quot;InOZJd_2l&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 4px 0px 0px;&quot;&gt;&lt;div data-processed=&quot;true&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;rq1a2&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 0px;&quot;&gt;&lt;div class=&quot;a2TNg&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;GlO4G&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; margin: 0px;&quot;&gt;sql&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;PGvq2d&quot; dir=&quot;ltr&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;pre style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 14px 0px;&quot;&gt;&lt;code jsuid=&quot;InOZJd_2n&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- 1. CREATE TABLE SCHEMA&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;CREATE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;TABLE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees (
    employee_id INT &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;PRIMARY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;KEY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;,
    employee_name VARCHAR(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
    department VARCHAR(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
    salary &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;DECIMAL&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;)
);

&lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- 2. INSERT SAMPLE DATA&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Total Salary = 430,000 | Average Salary = 86,000&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;INSERT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;INTO&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees (employee_id, employee_name, department, salary) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;VALUES&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Alice Smith&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Engineering&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;95000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),  &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Above Average&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Bob Jones&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Sales&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;75000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),            &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Below Average&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Diana Prince&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Marketing&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;82000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),      &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Below Average&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Fiona Gallagher&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Engineering&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;110000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Above Average&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Hannah Abbott&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Marketing&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;68000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;);    &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Below Average&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- 3. EXECUTE FILTERED QUERY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; 
    employee_name,
    department,
    salary
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;WHERE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; salary &amp;gt; (&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; AVG(salary) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees)
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;ORDER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;BY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; salary &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;DESC&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;iMHp6c&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 3px 0px 0px;&quot;&gt;&lt;div class=&quot;ZIumpf&quot; style=&quot;border-bottom: 0px rgb(32, 33, 36); font-size: 12px; margin: 0px;&quot;&gt;Use code with caution.&lt;/div&gt;&lt;span data-ved=&quot;2ahUKEwjCpdj87dqXAxWd1TgGHQMCIn4QopQPegYIAAgYEAE&quot; jsaction=&quot;action:&amp;amp;InOZJd_2l|ZUljYd&quot; jsuid=&quot;InOZJd_2m&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwjCpdj87dqXAxWd1TgGHQMCIn4Qh9gSegYIAAgYEAI&quot; jsaction=&quot;&quot; jscontroller=&quot;cXTEid#e0nEwf&quot; jsuid=&quot;InOZJd_2o&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd||GVEHxc=*Q0pj3b|[]--&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;!--TgQPHd|||[[&amp;quot;sql&amp;quot;,&amp;quot;-- 1. CREATE TABLE SCHEMA\nCREATE TABLE employees (\n    employee_id INT PRIMARY KEY,\n    employee_name VARCHAR(100),\n    department VARCHAR(50),\n    salary DECIMAL(10, 2)\n);\n\n-- 2. INSERT SAMPLE DATA\n-- Total Salary \u003d 430,000 | Average Salary \u003d 86,000\nINSERT INTO employees (employee_id, employee_name, department, salary) VALUES\n(1, &amp;#39;Alice Smith&amp;#39;, &amp;#39;Engineering&amp;#39;, 95000.00),  -- Above Average\n(2, &amp;#39;Bob Jones&amp;#39;, &amp;#39;Sales&amp;#39;, 75000.00),            -- Below Average\n(3, &amp;#39;Diana Prince&amp;#39;, &amp;#39;Marketing&amp;#39;, 82000.00),      -- Below Average\n(4, &amp;#39;Fiona Gallagher&amp;#39;, &amp;#39;Engineering&amp;#39;, 110000.00),-- Above Average\n(5, &amp;#39;Hannah Abbott&amp;#39;, &amp;#39;Marketing&amp;#39;, 68000.00);    -- Below Average\n\n-- 3. EXECUTE FILTERED QUERY\nSELECT \n    employee_name,\n    department,\n    salary\nFROM employees\nWHERE salary \u003e (SELECT AVG(salary) FROM employees)\nORDER BY salary DESC;\n&amp;quot;,[[&amp;quot;-- 1. CREATE TABLE SCHEMA&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;CREATE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;TABLE&amp;quot;,3],[&amp;quot; employees (\n    employee_id INT &amp;quot;,0],[&amp;quot;PRIMARY&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;KEY&amp;quot;,3],[&amp;quot;,\n    employee_name VARCHAR(&amp;quot;,0],[&amp;quot;100&amp;quot;,6],[&amp;quot;),\n    department VARCHAR(&amp;quot;,0],[&amp;quot;50&amp;quot;,6],[&amp;quot;),\n    salary &amp;quot;,0],[&amp;quot;DECIMAL&amp;quot;,3],[&amp;quot;(&amp;quot;,0],[&amp;quot;10&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;2&amp;quot;,6],[&amp;quot;)\n);\n\n&amp;quot;,0],[&amp;quot;-- 2. INSERT SAMPLE DATA&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;-- Total Salary \u003d 430,000 | Average Salary \u003d 86,000&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;INSERT&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;INTO&amp;quot;,3],[&amp;quot; employees (employee_id, employee_name, department, salary) &amp;quot;,0],[&amp;quot;VALUES&amp;quot;,3],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Alice Smith&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Engineering&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;95000.00&amp;quot;,6],[&amp;quot;),  &amp;quot;,0],[&amp;quot;-- Above Average&amp;quot;,5],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;2&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Bob Jones&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Sales&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;75000.00&amp;quot;,6],[&amp;quot;),            &amp;quot;,0],[&amp;quot;-- Below Average&amp;quot;,5],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;3&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Diana Prince&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Marketing&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;82000.00&amp;quot;,6],[&amp;quot;),      &amp;quot;,0],[&amp;quot;-- Below Average&amp;quot;,5],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;4&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Fiona Gallagher&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Engineering&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;110000.00&amp;quot;,6],[&amp;quot;),&amp;quot;,0],[&amp;quot;-- Above Average&amp;quot;,5],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;5&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Hannah Abbott&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Marketing&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;68000.00&amp;quot;,6],[&amp;quot;);    &amp;quot;,0],[&amp;quot;-- Below Average&amp;quot;,5],[&amp;quot;\n\n&amp;quot;,0],[&amp;quot;-- 3. EXECUTE FILTERED QUERY&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; \n    employee_name,\n    department,\n    salary\n&amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; employees\n&amp;quot;,0],[&amp;quot;WHERE&amp;quot;,3],[&amp;quot; salary \u003e (&amp;quot;,0],[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; AVG(salary) &amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; employees)\n&amp;quot;,0],[&amp;quot;ORDER&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;BY&amp;quot;,3],[&amp;quot; salary &amp;quot;,0],[&amp;quot;DESC&amp;quot;,3],[&amp;quot;;\n&amp;quot;,0]]]]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_2s|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;InOZJd_2s&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=InOZJd_2t/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;InOZJd_2t&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;Expected Query Output&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIGhAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;InOZJd_2u&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;With a company average of &lt;span class=&quot;rQesXe MPyX&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;tP2kf#s32ZS&quot; jsuid=&quot;InOZJd_2v&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;&lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;InOZJd_2w&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;86,000.00&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;, the query filters out the lower salaries and yields:&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_32|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;InOZJd_32&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;Fv6NCb&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIGxAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwjCpdj87dqXAxWd1TgGHQMCIn4Q-q4QegYIAAgbEAA&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_33|npT2md;scroll:&amp;amp;InOZJd_33|ZUljYd&quot; jscontroller=&quot;kbUand#UYOFMe&quot; jsuid=&quot;InOZJd_33&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 4px 0px 12px;&quot;&gt;&lt;table class=&quot;NRefec&quot; data-animation-nesting=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 14px; margin: 0px;&quot;&gt;&lt;tbody style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwjCpdj87dqXAxWd1TgGHQMCIn4Qw4oVegYIAAgbEAE&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;InOZJd_34&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;th class=&quot;BSFG4e&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;qmn2r#iLQbnd&quot; jsuid=&quot;InOZJd_35&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;employee_name&lt;!--TgQPHd|||[]--&gt;&lt;/th&gt;&lt;th class=&quot;BSFG4e&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;qmn2r#iLQbnd&quot; jsuid=&quot;InOZJd_36&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;department&lt;!--TgQPHd|||[]--&gt;&lt;/th&gt;&lt;th class=&quot;BSFG4e&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;qmn2r#iLQbnd&quot; jsuid=&quot;InOZJd_37&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;salary&lt;!--TgQPHd|||[]--&gt;&lt;/th&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwjCpdj87dqXAxWd1TgGHQMCIn4Qw4oVegYIAAgbEAI&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;InOZJd_38&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;InOZJd_39&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Fiona Gallagher&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;InOZJd_3a&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Engineering&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;InOZJd_3b&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;110000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwjCpdj87dqXAxWd1TgGHQMCIn4Qw4oVegYIAAgbEAM&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;InOZJd_3c&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;InOZJd_3d&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;Alice Smith&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;InOZJd_3e&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;Engineering&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;InOZJd_3f&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;95000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;!--TgQPHd|||[[1,0,0,3,null,&amp;quot;&amp;quot;]]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_3g|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;InOZJd_3g&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;AHmQrc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIHBAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;LkYPVc#wdvZmf&quot; jsuid=&quot;InOZJd_3h&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIHBAB&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;InOZJd_3i&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;&lt;br /&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_3q|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;InOZJd_3q&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_3s|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;InOZJd_3s&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_6b|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;InOZJd_6b&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-subtree=&quot;aimba&quot; jsaction=&quot;&quot; jscontroller=&quot;v48bt#VKyOOd&quot; jsuid=&quot;InOZJd_6c&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;SGF5Lb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;mk5ZW#TASLyc&quot; jsuid=&quot;InOZJd_8&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;SGF5Lb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;mk5ZW#TASLyc&quot; jsuid=&quot;InOZJd_9&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;SGF5Lb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;mk5ZW#TASLyc&quot; jsuid=&quot;InOZJd_a&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;&quot; data-complete=&quot;true&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;zp3Dsd#fP0RJ&quot; jsuid=&quot;InOZJd_b&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div data-xid=&quot;aQR2uf&quot; jsaction=&quot;aimRestoredThreadVisible:&amp;amp;InOZJd_1|ZUljYd;requestToggleBottomSheet:&amp;amp;InOZJd_1|aXD3Gb&quot; jsuid=&quot;InOZJd_2&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;/div&gt;&lt;div data-complete=&quot;true&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;InOZJd_h,InOZJd_i&quot; jsaction=&quot;rcuQ6b:&amp;amp;InOZJd_g|npT2md&quot; jscontroller=&quot;CAwPlc#Hx4Oqd&quot; jsuid=&quot;InOZJd_g&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;!--TgQPHdInOZJd_1/YOIIaf;InOZJd_1/VWapad|||[{&amp;quot;s&amp;quot;:false,&amp;quot;i&amp;quot;:&amp;quot;InOZJd_1/YOIIaf&amp;quot;},{&amp;quot;s&amp;quot;:null,&amp;quot;i&amp;quot;:&amp;quot;InOZJd_1/VWapad&amp;quot;},156,{&amp;quot;s&amp;quot;:null,&amp;quot;i&amp;quot;:&amp;quot;InOZJd_1/C5DOxd&amp;quot;},[&amp;quot;AimExportActionToastLink&amp;quot;,309275],&amp;quot;\u0026InOZJd_1:bREfu&amp;quot;,false]--&gt;&lt;/div&gt;&lt;!--TgQPHd|InOZJd_1/YOIIaf;InOZJd_1/We76zc;InOZJd_1/LL5gb;InOZJd_1/C5DOxd;InOZJd_1/VWapad||[[null,0,null,0,null,0,[&amp;quot;Write a query to find employees with salary greater than average salary in\nthe entire company, ordered by salary descending.&amp;quot;],null,0,[&amp;quot;Write a query to find employees with salary greater than average salary in\nthe entire company, ordered by salary descending.&amp;quot;],0]]--&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/2704674583668641563/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/write-query-to-find-employees-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/2704674583668641563'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/2704674583668641563'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/11/write-query-to-find-employees-with.html' title='Write a query to find employees with salary greater than average salary in the entire company, ordered by salary descending.'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-3387015813438561295</id><published>2026-10-31T20:30:00.000-07:00</published><updated>2026-10-31T20:30:00.121-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Write a query to calculate the difference between current row and previous row&#39;s salary (lag function).</title><content type='html'>&lt;div class=&quot;pWvJNd&quot; data-complete=&quot;true&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;zp3Dsd#fP0RJ&quot; jsuid=&quot;MkQeue_5&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;div data-complete=&quot;true&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;z34MU#CsVNRe&quot; jsname=&quot;s7e4Od&quot; jsuid=&quot;MkQeue_6&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;mZJni&quot; data-container-id=&quot;main-col&quot; data-ctx-provider=&quot;[[[&amp;quot;dMtGDc&amp;quot;,&amp;quot;[false]&amp;quot;]]]&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwi42bLE7dqXAxUZzTgGHQkADkYQ3KYQegYIAAgHEAE&quot; data-xid=&quot;VpUvz&quot; dir=&quot;ltr&quot; jsaction=&quot;cC6SSe:&amp;amp;MkQeue_7|mNzCb;&quot; jscontroller=&quot;Aoijq#INwBm&quot; jsname=&quot;KFl8ub&quot; jsuid=&quot;MkQeue_7&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAICxAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;MkQeue_o&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;&lt;span data-processed=&quot;true&quot; data-subtree=&quot;aimfl&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;To calculate the difference between the current row&#39;s salary and the previous row&#39;s salary, you use the &lt;/span&gt;&lt;span class=&quot;rQesXe MPyX&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;tP2kf#s32ZS&quot; jsuid=&quot;MkQeue_q&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;&lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;MkQeue_r&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;LAG()&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt; window function. &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;MkQeue_s&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;LAG()&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; allows you to look backward at a previous row&#39;s data within your result set without executing a complex self-join.&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;MkQeue_y|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;MkQeue_y&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=MkQeue_z/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;MkQeue_z&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;The Query&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIDRAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;MkQeue_10&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;Here is the standard SQL query. It orders the employees by salary (highest to lowest) and computes the exact structural difference between adjacent positions:&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;MkQeue_16|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;MkQeue_16&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;BpxUDf aiModeUiCodeBlock__Container&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIDhAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;MkQeue_19,MkQeue_18&quot; jsaction=&quot;&quot; jscontroller=&quot;Liu6s#lcO7sb&quot; jsuid=&quot;MkQeue_17&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 4px 0px 0px;&quot;&gt;&lt;div data-processed=&quot;true&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;rq1a2&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 0px;&quot;&gt;&lt;div class=&quot;a2TNg&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;GlO4G&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; margin: 0px;&quot;&gt;sql&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;PGvq2d&quot; dir=&quot;ltr&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;pre style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 14px 0px;&quot;&gt;&lt;code jsuid=&quot;MkQeue_19&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; 
    employee_id,
    employee_name,
    department,
    salary,
    &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Step 1: Fetch the previous row&#39;s salary&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
    LAG(salary, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;OVER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;ORDER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;BY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; salary &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;DESC&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; previous_salary,
    
    &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Step 2: Subtract the previous row&#39;s salary from the current row&#39;s salary&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
    salary - LAG(salary, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, salary) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;OVER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;ORDER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;BY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; salary &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;DESC&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; salary_difference
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;iMHp6c&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 3px 0px 0px;&quot;&gt;&lt;div class=&quot;ZIumpf&quot; style=&quot;border-bottom: 0px rgb(32, 33, 36); font-size: 12px; margin: 0px;&quot;&gt;Use code with caution.&lt;/div&gt;&lt;span data-ved=&quot;2ahUKEwi42bLE7dqXAxUZzTgGHQkADkYQopQPegYIAAgOEAE&quot; jsaction=&quot;action:&amp;amp;MkQeue_17|ZUljYd&quot; jsuid=&quot;MkQeue_18&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwi42bLE7dqXAxUZzTgGHQkADkYQh9gSegYIAAgOEAI&quot; jsaction=&quot;&quot; jscontroller=&quot;cXTEid#e0nEwf&quot; jsuid=&quot;MkQeue_1a&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd||GVEHxc=*Q0pj3b|[]--&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;!--TgQPHd|||[[&amp;quot;sql&amp;quot;,&amp;quot;SELECT \n    employee_id,\n    employee_name,\n    department,\n    salary,\n    -- Step 1: Fetch the previous row&amp;#39;s salary\n    LAG(salary, 1, 0) OVER (ORDER BY salary DESC) AS previous_salary,\n    \n    -- Step 2: Subtract the previous row&amp;#39;s salary from the current row&amp;#39;s salary\n    salary - LAG(salary, 1, salary) OVER (ORDER BY salary DESC) AS salary_difference\nFROM employees;\n&amp;quot;,[[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; \n    employee_id,\n    employee_name,\n    department,\n    salary,\n    &amp;quot;,0],[&amp;quot;-- Step 1: Fetch the previous row&amp;#39;s salary&amp;quot;,5],[&amp;quot;\n    LAG(salary, &amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;0&amp;quot;,6],[&amp;quot;) &amp;quot;,0],[&amp;quot;OVER&amp;quot;,3],[&amp;quot; (&amp;quot;,0],[&amp;quot;ORDER&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;BY&amp;quot;,3],[&amp;quot; salary &amp;quot;,0],[&amp;quot;DESC&amp;quot;,3],[&amp;quot;) &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; previous_salary,\n    \n    &amp;quot;,0],[&amp;quot;-- Step 2: Subtract the previous row&amp;#39;s salary from the current row&amp;#39;s salary&amp;quot;,5],[&amp;quot;\n    salary - LAG(salary, &amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot;, salary) &amp;quot;,0],[&amp;quot;OVER&amp;quot;,3],[&amp;quot; (&amp;quot;,0],[&amp;quot;ORDER&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;BY&amp;quot;,3],[&amp;quot; salary &amp;quot;,0],[&amp;quot;DESC&amp;quot;,3],[&amp;quot;) &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; salary_difference\n&amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; employees;\n&amp;quot;,0]]]]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;MkQeue_1e|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;MkQeue_1e&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=MkQeue_1f/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;MkQeue_1f&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;Syntax Deep Dive: &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;MkQeue_1g&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;LAG(column, offset, default)&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;ul class=&quot;XSq4R KI3fJ&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;wiLEJc#NS0kde&quot; jsuid=&quot;MkQeue_1h&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;&lt;li class=&quot;Z1qcYe&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAB&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;oSLmPe#HokZ0d&quot; jsuid=&quot;MkQeue_1i&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px 0px 12px;&quot;&gt;&lt;span class=&quot;iNqyIf&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;KdQfFc#d5Qebf&quot; jsuid=&quot;MkQeue_1j&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;rQesXe MPyX&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;tP2kf#s32ZS&quot; jsuid=&quot;MkQeue_1k&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;&lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;MkQeue_1l&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;salary&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;:&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt; The target column you want to retrieve a historical value from.&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/li&gt;&lt;li class=&quot;Z1qcYe&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAE&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;oSLmPe#HokZ0d&quot; jsuid=&quot;MkQeue_1r&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px 0px 12px;&quot;&gt;&lt;span class=&quot;iNqyIf&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;KdQfFc#d5Qebf&quot; jsuid=&quot;MkQeue_1s&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;rQesXe MPyX&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;tP2kf#s32ZS&quot; jsuid=&quot;MkQeue_1t&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;&lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;MkQeue_1u&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;1&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; (Offset):&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt; How many rows to look backward. A value of &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;MkQeue_1v&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;1&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; targets the immediate previous row.&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/li&gt;&lt;li class=&quot;Z1qcYe&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAH&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;oSLmPe#HokZ0d&quot; jsuid=&quot;MkQeue_21&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;iNqyIf&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;KdQfFc#d5Qebf&quot; jsuid=&quot;MkQeue_22&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;rQesXe MPyX&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;tP2kf#s32ZS&quot; jsuid=&quot;MkQeue_23&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;&lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;MkQeue_24&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;0&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; or &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;MkQeue_25&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;salary&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; (Default Value):&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt; What to return if there is no previous row (e.g., the very first row in the dataset).&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;ul class=&quot;XSq4R KI3fJ&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAI&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;wiLEJc#NS0kde&quot; jsuid=&quot;MkQeue_26&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 12px 0px 16px;&quot;&gt;&lt;li class=&quot;Z1qcYe&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAJ&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;oSLmPe#HokZ0d&quot; jsuid=&quot;MkQeue_27&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px 0px 12px;&quot;&gt;&lt;span class=&quot;iNqyIf&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;KdQfFc#d5Qebf&quot; jsuid=&quot;MkQeue_28&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;Passing &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;MkQeue_29&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;0&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; or omitting it helps show a blank baseline.&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/li&gt;&lt;li class=&quot;Z1qcYe&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAK&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;oSLmPe#HokZ0d&quot; jsuid=&quot;MkQeue_2a&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px 0px 12px;&quot;&gt;&lt;span class=&quot;iNqyIf&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;KdQfFc#d5Qebf&quot; jsuid=&quot;MkQeue_2b&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;Passing the column itself (&lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;MkQeue_2c&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;salary&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;) ensures that subtracting it from the current row results in a clean &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;MkQeue_2d&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;0&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; instead of a breaking &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;MkQeue_2e&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;NULL&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; value on row one.&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/li&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/ul&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/li&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/ul&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;MkQeue_2k|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;MkQeue_2k&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;hr class=&quot;s6NV4e&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-pl=&quot;|||[]&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;gWGJ0d#iOlsLd&quot; jsuid=&quot;MkQeue_2l&quot; style=&quot;border-bottom: 0px rgb(128, 128, 128); margin: 32px 0px;&quot; /&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;MkQeue_2m|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;MkQeue_2m&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=MkQeue_2n/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;MkQeue_2n&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;Complete Playground Script (Schema + Test Data)&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIExAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;MkQeue_2o&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;Copy and execute this script to test the calculations live:&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;MkQeue_2u|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;MkQeue_2u&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;BpxUDf aiModeUiCodeBlock__Container&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIFBAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;MkQeue_2x,MkQeue_2w&quot; jsaction=&quot;&quot; jscontroller=&quot;Liu6s#lcO7sb&quot; jsuid=&quot;MkQeue_2v&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 4px 0px 0px;&quot;&gt;&lt;div data-processed=&quot;true&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;rq1a2&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 0px;&quot;&gt;&lt;div class=&quot;a2TNg&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;GlO4G&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; margin: 0px;&quot;&gt;sql&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;PGvq2d&quot; dir=&quot;ltr&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;pre style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 14px 0px;&quot;&gt;&lt;code jsuid=&quot;MkQeue_2x&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- 1. CREATE TABLE SCHEMA&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;CREATE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;TABLE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees (
    employee_id INT &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;PRIMARY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;KEY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;,
    employee_name VARCHAR(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
    department VARCHAR(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
    salary &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;DECIMAL&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;)
);

&lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- 2. INSERT SAMPLE DATA&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;INSERT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;INTO&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees (employee_id, employee_name, department, salary) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;VALUES&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Alice Smith&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Engineering&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;95000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Bob Jones&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Sales&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;75000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Diana Prince&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Marketing&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;82000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Fiona Gallagher&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Engineering&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;110000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Hannah Abbott&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Marketing&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;68000.00&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;);

&lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- 3. EXECUTE LAG QUERY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; 
    employee_name,
    department,
    salary,
    LAG(salary, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;OVER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;ORDER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;BY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; salary &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;DESC&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; previous_employee_salary,
    salary - LAG(salary, &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, salary) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;OVER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;ORDER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;BY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; salary &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;DESC&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; salary_diff_from_previous
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;iMHp6c&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 3px 0px 0px;&quot;&gt;&lt;div class=&quot;ZIumpf&quot; style=&quot;border-bottom: 0px rgb(32, 33, 36); font-size: 12px; margin: 0px;&quot;&gt;Use code with caution.&lt;/div&gt;&lt;span data-ved=&quot;2ahUKEwi42bLE7dqXAxUZzTgGHQkADkYQopQPegYIAAgUEAE&quot; jsaction=&quot;action:&amp;amp;MkQeue_2v|ZUljYd&quot; jsuid=&quot;MkQeue_2w&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwi42bLE7dqXAxUZzTgGHQkADkYQh9gSegYIAAgUEAI&quot; jsaction=&quot;&quot; jscontroller=&quot;cXTEid#e0nEwf&quot; jsuid=&quot;MkQeue_2y&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd||GVEHxc=*Q0pj3b|[]--&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;!--TgQPHd|||[[&amp;quot;sql&amp;quot;,&amp;quot;-- 1. CREATE TABLE SCHEMA\nCREATE TABLE employees (\n    employee_id INT PRIMARY KEY,\n    employee_name VARCHAR(100),\n    department VARCHAR(50),\n    salary DECIMAL(10, 2)\n);\n\n-- 2. INSERT SAMPLE DATA\nINSERT INTO employees (employee_id, employee_name, department, salary) VALUES\n(1, &amp;#39;Alice Smith&amp;#39;, &amp;#39;Engineering&amp;#39;, 95000.00),\n(2, &amp;#39;Bob Jones&amp;#39;, &amp;#39;Sales&amp;#39;, 75000.00),\n(3, &amp;#39;Diana Prince&amp;#39;, &amp;#39;Marketing&amp;#39;, 82000.00),\n(4, &amp;#39;Fiona Gallagher&amp;#39;, &amp;#39;Engineering&amp;#39;, 110000.00),\n(5, &amp;#39;Hannah Abbott&amp;#39;, &amp;#39;Marketing&amp;#39;, 68000.00);\n\n-- 3. EXECUTE LAG QUERY\nSELECT \n    employee_name,\n    department,\n    salary,\n    LAG(salary, 1) OVER (ORDER BY salary DESC) AS previous_employee_salary,\n    salary - LAG(salary, 1, salary) OVER (ORDER BY salary DESC) AS salary_diff_from_previous\nFROM employees;\n&amp;quot;,[[&amp;quot;-- 1. CREATE TABLE SCHEMA&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;CREATE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;TABLE&amp;quot;,3],[&amp;quot; employees (\n    employee_id INT &amp;quot;,0],[&amp;quot;PRIMARY&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;KEY&amp;quot;,3],[&amp;quot;,\n    employee_name VARCHAR(&amp;quot;,0],[&amp;quot;100&amp;quot;,6],[&amp;quot;),\n    department VARCHAR(&amp;quot;,0],[&amp;quot;50&amp;quot;,6],[&amp;quot;),\n    salary &amp;quot;,0],[&amp;quot;DECIMAL&amp;quot;,3],[&amp;quot;(&amp;quot;,0],[&amp;quot;10&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;2&amp;quot;,6],[&amp;quot;)\n);\n\n&amp;quot;,0],[&amp;quot;-- 2. INSERT SAMPLE DATA&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;INSERT&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;INTO&amp;quot;,3],[&amp;quot; employees (employee_id, employee_name, department, salary) &amp;quot;,0],[&amp;quot;VALUES&amp;quot;,3],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Alice Smith&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Engineering&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;95000.00&amp;quot;,6],[&amp;quot;),\n(&amp;quot;,0],[&amp;quot;2&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Bob Jones&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Sales&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;75000.00&amp;quot;,6],[&amp;quot;),\n(&amp;quot;,0],[&amp;quot;3&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Diana Prince&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Marketing&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;82000.00&amp;quot;,6],[&amp;quot;),\n(&amp;quot;,0],[&amp;quot;4&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Fiona Gallagher&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Engineering&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;110000.00&amp;quot;,6],[&amp;quot;),\n(&amp;quot;,0],[&amp;quot;5&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Hannah Abbott&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Marketing&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;68000.00&amp;quot;,6],[&amp;quot;);\n\n&amp;quot;,0],[&amp;quot;-- 3. EXECUTE LAG QUERY&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; \n    employee_name,\n    department,\n    salary,\n    LAG(salary, &amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot;) &amp;quot;,0],[&amp;quot;OVER&amp;quot;,3],[&amp;quot; (&amp;quot;,0],[&amp;quot;ORDER&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;BY&amp;quot;,3],[&amp;quot; salary &amp;quot;,0],[&amp;quot;DESC&amp;quot;,3],[&amp;quot;) &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; previous_employee_salary,\n    salary - LAG(salary, &amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot;, salary) &amp;quot;,0],[&amp;quot;OVER&amp;quot;,3],[&amp;quot; (&amp;quot;,0],[&amp;quot;ORDER&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;BY&amp;quot;,3],[&amp;quot; salary &amp;quot;,0],[&amp;quot;DESC&amp;quot;,3],[&amp;quot;) &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; salary_diff_from_previous\n&amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; employees;\n&amp;quot;,0]]]]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;MkQeue_32|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;MkQeue_32&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=MkQeue_33/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;MkQeue_33&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;Expected Query Output&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;MkQeue_34|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;MkQeue_34&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;Fv6NCb&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIFhAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwi42bLE7dqXAxUZzTgGHQkADkYQ-q4QegYIAAgWEAA&quot; jsaction=&quot;rcuQ6b:&amp;amp;MkQeue_35|npT2md;scroll:&amp;amp;MkQeue_35|ZUljYd&quot; jscontroller=&quot;kbUand#UYOFMe&quot; jsuid=&quot;MkQeue_35&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 4px 0px 12px;&quot;&gt;&lt;table class=&quot;NRefec&quot; data-animation-nesting=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 14px; margin: 0px;&quot;&gt;&lt;tbody style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwi42bLE7dqXAxUZzTgGHQkADkYQw4oVegYIAAgWEAE&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;MkQeue_36&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;th class=&quot;BSFG4e&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;qmn2r#iLQbnd&quot; jsuid=&quot;MkQeue_37&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;employee_name&lt;!--TgQPHd|||[]--&gt;&lt;/th&gt;&lt;th class=&quot;BSFG4e&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;qmn2r#iLQbnd&quot; jsuid=&quot;MkQeue_38&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;department&lt;!--TgQPHd|||[]--&gt;&lt;/th&gt;&lt;th class=&quot;BSFG4e&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;qmn2r#iLQbnd&quot; jsuid=&quot;MkQeue_39&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;salary&lt;!--TgQPHd|||[]--&gt;&lt;/th&gt;&lt;th class=&quot;BSFG4e&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;qmn2r#iLQbnd&quot; jsuid=&quot;MkQeue_3a&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;previous_employee_salary&lt;!--TgQPHd|||[]--&gt;&lt;/th&gt;&lt;th class=&quot;BSFG4e&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;qmn2r#iLQbnd&quot; jsuid=&quot;MkQeue_3b&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;salary_diff_from_previous&lt;!--TgQPHd|||[]--&gt;&lt;/th&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwi42bLE7dqXAxUZzTgGHQkADkYQw4oVegYIAAgWEAI&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;MkQeue_3c&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3d&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Fiona Gallagher&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3e&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Engineering&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3f&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;110000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3g&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;&lt;em class=&quot;zhvwWe&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;LFsGHb#ycPkjf&quot; jsuid=&quot;MkQeue_3h&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;NULL&lt;!--TgQPHd|||[]--&gt;&lt;/em&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3i&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;0.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwi42bLE7dqXAxUZzTgGHQkADkYQw4oVegYIAAgWEAM&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;MkQeue_3j&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3k&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Alice Smith&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3l&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Engineering&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3m&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;95000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3n&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;110000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3o&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;-15000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwi42bLE7dqXAxUZzTgGHQkADkYQw4oVegYIAAgWEAQ&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;MkQeue_3p&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3q&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Diana Prince&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3r&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Marketing&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3s&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;82000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3t&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;95000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3u&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;-13000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwi42bLE7dqXAxUZzTgGHQkADkYQw4oVegYIAAgWEAU&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;MkQeue_3v&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3w&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Bob Jones&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3x&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Sales&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3y&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;75000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_3z&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;82000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_40&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;-7000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwi42bLE7dqXAxUZzTgGHQkADkYQw4oVegYIAAgWEAY&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;MkQeue_41&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_42&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;Hannah Abbott&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_43&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;Marketing&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_44&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;68000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_45&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;75000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;MkQeue_46&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;-7000.00&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;!--TgQPHd|||[[1,0,0,5,null,&amp;quot;&amp;quot;]]--&gt;&lt;/div&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIFxAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;MkQeue_47&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;&lt;em class=&quot;zhvwWe&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;LFsGHb#ycPkjf&quot; jsuid=&quot;MkQeue_48&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;(Note: Fiona displays &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;MkQeue_49&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;0.00&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; difference because she is at the top of the chain; there is no previous record to subtract from her total.)&lt;!--TgQPHd|||[]--&gt;&lt;/em&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;MkQeue_4f|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;MkQeue_4f&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;AHmQrc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIGBAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;LkYPVc#wdvZmf&quot; jsuid=&quot;MkQeue_4g&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIGBAB&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;MkQeue_4h&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;&lt;br /&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;MkQeue_4s|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;MkQeue_4s&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;MkQeue_4u|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;MkQeue_4u&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;MkQeue_77|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;MkQeue_77&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-subtree=&quot;aimba&quot; jsaction=&quot;&quot; jscontroller=&quot;v48bt#VKyOOd&quot; jsuid=&quot;MkQeue_78&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;SGF5Lb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;mk5ZW#TASLyc&quot; jsuid=&quot;MkQeue_8&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;SGF5Lb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;mk5ZW#TASLyc&quot; jsuid=&quot;MkQeue_9&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;SGF5Lb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;mk5ZW#TASLyc&quot; jsuid=&quot;MkQeue_a&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;&quot; data-complete=&quot;true&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;zp3Dsd#fP0RJ&quot; jsuid=&quot;MkQeue_b&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div data-xid=&quot;aQR2uf&quot; jsaction=&quot;aimRestoredThreadVisible:&amp;amp;MkQeue_1|ZUljYd;requestToggleBottomSheet:&amp;amp;MkQeue_1|aXD3Gb&quot; jsuid=&quot;MkQeue_2&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;/div&gt;&lt;div data-complete=&quot;true&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;MkQeue_h,MkQeue_i&quot; jsaction=&quot;rcuQ6b:&amp;amp;MkQeue_g|npT2md&quot; jscontroller=&quot;CAwPlc#Hx4Oqd&quot; jsuid=&quot;MkQeue_g&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;!--TgQPHdMkQeue_1/VWapad;MkQeue_1/YOIIaf|||[{&amp;quot;s&amp;quot;:false,&amp;quot;i&amp;quot;:&amp;quot;MkQeue_1/YOIIaf&amp;quot;},{&amp;quot;s&amp;quot;:null,&amp;quot;i&amp;quot;:&amp;quot;MkQeue_1/VWapad&amp;quot;},156,{&amp;quot;s&amp;quot;:null,&amp;quot;i&amp;quot;:&amp;quot;MkQeue_1/C5DOxd&amp;quot;},[&amp;quot;AimExportActionToastLink&amp;quot;,309275],&amp;quot;\u0026MkQeue_1:bREfu&amp;quot;,false]--&gt;&lt;/div&gt;&lt;!--TgQPHd|MkQeue_1/C5DOxd;MkQeue_1/LL5gb;MkQeue_1/VWapad;MkQeue_1/YOIIaf;MkQeue_1/We76zc||[[null,0,null,0,null,0,[&amp;quot;Write a query to calculate the difference between current row and\nprevious row&amp;#39;s salary (lag function).&amp;quot;],null,0,[&amp;quot;Write a query to calculate the difference between current row and\nprevious row&amp;#39;s salary (lag function).&amp;quot;],0]]--&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/3387015813438561295/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/write-query-to-calculate-difference.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/3387015813438561295'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/3387015813438561295'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/write-query-to-calculate-difference.html' title='Write a query to calculate the difference between current row and previous row&#39;s salary (lag function).'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-5672783860780755259</id><published>2026-10-31T20:30:00.000-07:00</published><updated>2026-10-31T20:30:00.121-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><title type='text'>What is the difference between a Service Bus Queue and a Topic?</title><content type='html'>&lt;h1&gt;Service Bus Queue vs. Topic&lt;/h1&gt;
&lt;p&gt;The core difference is the delivery model: a &lt;strong&gt;queue&lt;/strong&gt; delivers each message to exactly one consumer, while a &lt;strong&gt;topic&lt;/strong&gt; delivers a copy of each message to every interested subscriber.&lt;/p&gt;
&lt;h2&gt;Queue: point-to-point&lt;/h2&gt;
&lt;p&gt;Senders put messages on the queue, and receivers pull from it. If several receivers listen to the same queue, they are &lt;strong&gt;competing consumers&lt;/strong&gt;: each message goes to only one of them, so adding receivers spreads the load.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Sender(s) ──► [ Queue ] ──► Receiver A  (or B, or C; one gets each message)
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Topic: publish/subscribe&lt;/h2&gt;
&lt;p&gt;Senders publish to a topic, but receivers don&#39;t read from the topic itself. They read from &lt;strong&gt;subscriptions&lt;/strong&gt;, each of which acts like its own virtual queue. Every subscription receives its own copy of each message that matches its filter.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;                      ┌─► [ Subscription: billing ]   ──► Billing service
Sender ──► [ Topic ] ─┼─► [ Subscription: shipping ]  ──► Shipping service
                      └─► [ Subscription: analytics ] ──► Analytics service
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Within a single subscription, multiple consumers still compete, so you can scale out each subscriber independently.&lt;/p&gt;
&lt;h2&gt;Side-by-side&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Queue&lt;/th&gt;
&lt;th&gt;Topic + subscriptions&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Pattern&lt;/td&gt;
&lt;td&gt;Point-to-point&lt;/td&gt;
&lt;td&gt;Publish/subscribe (one-to-many)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Copies per message&lt;/td&gt;
&lt;td&gt;One, consumed once&lt;/td&gt;
&lt;td&gt;One per matching subscription&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Receivers read from&lt;/td&gt;
&lt;td&gt;The queue&lt;/td&gt;
&lt;td&gt;A subscription (not the topic)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sender knows the receivers?&lt;/td&gt;
&lt;td&gt;Effectively one logical consumer&lt;/td&gt;
&lt;td&gt;No, the sender is unaware of subscribers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Filtering&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;Rules and filters per subscription (SQL or correlation filters, with optional actions)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Adding a new consumer&lt;/td&gt;
&lt;td&gt;Competes with existing ones for messages&lt;/td&gt;
&lt;td&gt;Create a new subscription; existing ones are unaffected&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dead-letter queue&lt;/td&gt;
&lt;td&gt;One DLQ&lt;/td&gt;
&lt;td&gt;One DLQ per subscription&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tiers&lt;/td&gt;
&lt;td&gt;Standard and Premium&lt;/td&gt;
&lt;td&gt;Standard and Premium&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Filters on subscriptions&lt;/h2&gt;
&lt;p&gt;Topics get much of their power from subscription rules:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// Only receive orders from the EU
await adminClient.CreateSubscriptionAsync(
    new CreateSubscriptionOptions(&quot;orders&quot;, &quot;eu-orders&quot;),
    new CreateRuleOptions(&quot;EuOnly&quot;, new SqlRuleFilter(&quot;region = &#39;EU&#39;&quot;)));
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A subscription with no rule gets everything by default. Note that a subscription&#39;s default rule is &quot;match all&quot;, so if you add your own filter, remove the default rule or it will still match every message.&lt;/p&gt;
&lt;h2&gt;Sending and receiving in code&lt;/h2&gt;
&lt;p&gt;The code is nearly identical. The sender doesn&#39;t care which it targets, and only the receiver changes:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// Send (queue name or topic name)
var sender = client.CreateSender(&quot;orders&quot;);
await sender.SendMessageAsync(new ServiceBusMessage(&quot;Order #1234 placed&quot;));

// Receive from a queue
var queueReceiver = client.CreateReceiver(&quot;orders&quot;);

// Receive from a topic subscription
var subReceiver = client.CreateReceiver(&quot;orders&quot;, &quot;billing&quot;);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Because sending code is the same, you can start with a queue and move to a topic later without changing producers (you&#39;d recreate the entity, though, as a queue can&#39;t be converted into a topic).&lt;/p&gt;
&lt;h2&gt;When to use which&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Use a queue when:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;One service should process each message (work distribution, task processing).&lt;/li&gt;
&lt;li&gt;You want load leveling or competing consumers for throughput.&lt;/li&gt;
&lt;li&gt;The sender and receiver are tightly paired, e.g. &quot;process this payment.&quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Use a topic when:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Multiple independent systems must react to the same event (an &quot;order placed&quot; event consumed by billing, shipping, and notifications).&lt;/li&gt;
&lt;li&gt;Different consumers want different subsets of messages (via filters).&lt;/li&gt;
&lt;li&gt;You expect to add new consumers over time without touching the publisher.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Shared behavior&lt;/h2&gt;
&lt;p&gt;Queues and subscriptions share the same features: peek-lock, dead-lettering, sessions, scheduled messages, duplicate detection (configured at the topic level for topics), and TTL. A subscription is, in effect, a queue fed by a topic.&lt;/p&gt;
&lt;h2&gt;Rule of thumb&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Command&lt;/strong&gt; (&quot;do this work&quot;) → &lt;strong&gt;queue&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Event&lt;/strong&gt; (&quot;this happened&quot;) → &lt;strong&gt;topic&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you have a single consumer today but may add more, a topic with one subscription is a cheap way to keep your options open.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/5672783860780755259/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/what-is-difference-between-service-bus.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/5672783860780755259'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/5672783860780755259'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/what-is-difference-between-service-bus.html' title='What is the difference between a Service Bus Queue and a Topic?'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-496938955741482573</id><published>2026-10-30T20:30:00.000-07:00</published><updated>2026-10-30T20:30:00.121-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="API"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><title type='text'>Conventional vs. attribute routing?</title><content type='html'>With conventional routing, you map out all your URL patterns in one central route table. Attribute routing, on the other hand, lets you drop those rules directly onto the controller and action itself. The examples here use older tech like ASP.NET MVC 5 and Web API 2, but don&#39;t worry—the exact same concept applies to ASP.NET Core.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;
&lt;h2&gt;&lt;u&gt;Conventional routing:-&lt;/u&gt;&lt;/h2&gt;
&lt;p&gt;Patterns are registered once at startup file and apply to many controllers by naming convention.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute(&quot;{resource}.axd/{*pathInfo}&quot;);

    routes.MapRoute(
        name: &quot;Default&quot;,
        url: &quot;{controller}/{action}/{id}&quot;,
        defaults: new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional });
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;/Products/Details/5&lt;/code&gt; goes to &lt;code&gt;ProductsController.Details(5)&lt;/code&gt;. Add a new controller and its actions follow the same pattern with no extra routing code.&lt;/p&gt;
&lt;h2&gt;&lt;u&gt;Attribute routing:-&lt;/u&gt;&lt;/h2&gt;
&lt;p&gt;The URL is declared next to the code that handles it.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// RouteConfig: enable it BEFORE the conventional routes
routes.MapMvcAttributeRoutes();
// Web API 2: config.MapHttpAttributeRoutes();

[RoutePrefix(&quot;orders&quot;)]
public class OrdersController : Controller
{
    [Route(&quot;&quot;)]                              // /orders
    public ActionResult Index() { return View(); }

    [Route(&quot;{id:int}&quot;)]                      // /orders/42
    public ActionResult Details(int id) { return View(); }

    [Route(&quot;{id:int}/items/{itemId:int}&quot;)]   // /orders/42/items/7
    public ActionResult Item(int id, int itemId) { return View(); }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;&lt;u&gt;Differences:-&lt;/u&gt;&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Conventional&lt;/th&gt;
&lt;th&gt;Attribute&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Where defined&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Central route table (&lt;code&gt;RouteConfig&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;On controllers and actions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Style&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;One pattern serves many controllers&lt;/td&gt;
&lt;td&gt;One URL per action, explicit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;URL flexibility&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Best for uniform shapes like &lt;code&gt;{controller}/{action}/{id}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Handles irregular, nested, or custom URLs easily&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Readability&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;You must check the route table to know a URL&lt;/td&gt;
&lt;td&gt;The URL is visible right on the action&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Maintenance&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Change one rule to affect many actions&lt;/td&gt;
&lt;td&gt;Edit each action, but changes stay local&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Refactoring risk&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Renaming a controller or action changes its URL&lt;/td&gt;
&lt;td&gt;URLs stay stable when you rename methods&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Constraints&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Defined in the route&#39;s &lt;code&gt;constraints&lt;/code&gt; object&lt;/td&gt;
&lt;td&gt;Inline, such as &lt;code&gt;{id:int}&lt;/code&gt;, &lt;code&gt;{name:alpha}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Order&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;First match in the table wins, so order matters&lt;/td&gt;
&lt;td&gt;Rarely order-sensitive, but ambiguity still errors&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Best for&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Classic MVC sites with page-like URLs&lt;/td&gt;
&lt;td&gt;REST APIs, nested resources, SEO-friendly URLs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Why attribute routing is often preferred for APIs&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Nested resources&lt;/strong&gt; such as &lt;code&gt;/customers/{customerId}/orders/{orderId}&lt;/code&gt; are awkward to express with a global pattern.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Stable public URLs.&lt;/strong&gt; Renaming &lt;code&gt;GetOrder&lt;/code&gt; to &lt;code&gt;FetchOrder&lt;/code&gt; does not change &lt;code&gt;/orders/{id}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Optional parameters and defaults&lt;/strong&gt; can be written inline: &lt;code&gt;[Route(&quot;archive/{year:int?}&quot;)]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Route names&lt;/strong&gt; can be set for URL generation: &lt;code&gt;[Route(&quot;{id}&quot;, Name = &quot;OrderById&quot;)]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multiple URLs for one action&lt;/strong&gt; are possible by stacking attributes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;When conventional routing still fits&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;A traditional content site where nearly every page follows &lt;code&gt;{controller}/{action}/{id}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Many controllers that should behave uniformly, with no need to repeat a route on each one.&lt;/li&gt;
&lt;li&gt;A default homepage and catch-all fallbacks in a single place.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;You can mix both&lt;/h2&gt;
&lt;p&gt;A common setup uses attribute routes for specific or API-style URLs and a conventional default route for everything else. Register attribute routes &lt;strong&gt;first&lt;/strong&gt; so they take priority:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;routes.MapMvcAttributeRoutes();   // specific routes first

routes.MapRoute(                  // general fallback last
    name: &quot;Default&quot;,
    url: &quot;{controller}/{action}/{id}&quot;,
    defaults: new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional });
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Common mistakes&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Forgetting &lt;code&gt;MapMvcAttributeRoutes()&lt;/code&gt;.&lt;/strong&gt; The &lt;code&gt;[Route]&lt;/code&gt; attributes are silently ignored.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Calling it after the conventional route.&lt;/strong&gt; The general route can catch requests first.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Two actions matching the same URL and verb.&lt;/strong&gt; This throws an &quot;ambiguous match&quot; error. Use constraints or different templates.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Missing &lt;code&gt;[RoutePrefix]&lt;/code&gt; or typos in prefixes.&lt;/strong&gt; URLs end up different from what you intended.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mixing with Web API.&lt;/strong&gt; Web API has its own route table, so &lt;code&gt;MapHttpAttributeRoutes()&lt;/code&gt; is separate from &lt;code&gt;MapMvcAttributeRoutes()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;In ASP.NET Core&lt;/h2&gt;
&lt;p&gt;The same two ideas exist. Conventional routing uses &lt;code&gt;MapControllerRoute&lt;/code&gt;, and attribute routing uses &lt;code&gt;[Route]&lt;/code&gt;, &lt;code&gt;[HttpGet(&quot;...&quot;)]&lt;/code&gt;, and similar attributes. One key difference is that in Core, an action that has route attributes is &lt;strong&gt;not&lt;/strong&gt; reachable through conventional routes. Each action uses one style or the other.&lt;/p&gt;
&lt;h2&gt;Which one to choose?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Building an API?&lt;/strong&gt; Use attribute routing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Classic MVC site with uniform URLs?&lt;/strong&gt; Conventional routing is fine and less repetitive.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Need both?&lt;/strong&gt; Use attribute routes for the special cases and a conventional default as the fallback.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/496938955741482573/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/conventional-vs-attribute-routing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/496938955741482573'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/496938955741482573'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/conventional-vs-attribute-routing.html' title='Conventional vs. attribute routing?'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-3145056141671151266</id><published>2026-10-30T20:30:00.000-07:00</published><updated>2026-10-30T20:30:00.121-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql"/><title type='text'>Write a query to perform a conditional aggregation (count males and females in each department).</title><content type='html'>&lt;div class=&quot;pWvJNd&quot; data-complete=&quot;true&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;zp3Dsd#fP0RJ&quot; jsuid=&quot;snuBHc_5&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;div data-complete=&quot;true&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;z34MU#CsVNRe&quot; jsname=&quot;s7e4Od&quot; jsuid=&quot;snuBHc_6&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;mZJni&quot; data-container-id=&quot;main-col&quot; data-ctx-provider=&quot;[[[&amp;quot;dMtGDc&amp;quot;,&amp;quot;[false]&amp;quot;]]]&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwiN1rqG7dqXAxWRzTgGHZGwF2IQ3KYQegYIAAgIEAE&quot; data-xid=&quot;VpUvz&quot; dir=&quot;ltr&quot; jsaction=&quot;cC6SSe:&amp;amp;snuBHc_7|mNzCb;&quot; jscontroller=&quot;Aoijq#INwBm&quot; jsname=&quot;KFl8ub&quot; jsuid=&quot;snuBHc_7&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAICxAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;snuBHc_o&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;&lt;span data-processed=&quot;true&quot; data-subtree=&quot;aimfl&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;To perform conditional aggregation in SQL, you combine the &lt;/span&gt;&lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_q&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;SUM()&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; or &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_r&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;COUNT()&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; aggregate functions with a &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_s&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;CASE WHEN&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; statement. This allows you to inspect row attributes individually and increment separate totals within the same &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_t&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;GROUP BY&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; execution.&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;snuBHc_z|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;snuBHc_z&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=snuBHc_10/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;snuBHc_10&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;The Query&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIDRAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;snuBHc_11&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;Assuming your table is named &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_12&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;employees&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; and contains columns for &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_13&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;department&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; and &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_14&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;gender&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;, here is the standard, optimized SQL query:&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;snuBHc_1a|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;snuBHc_1a&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;BpxUDf aiModeUiCodeBlock__Container&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIDhAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;snuBHc_1d,snuBHc_1c&quot; jsaction=&quot;&quot; jscontroller=&quot;Liu6s#lcO7sb&quot; jsuid=&quot;snuBHc_1b&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 4px 0px 0px;&quot;&gt;&lt;div data-processed=&quot;true&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;rq1a2&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 0px;&quot;&gt;&lt;div class=&quot;a2TNg&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;GlO4G&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; margin: 0px;&quot;&gt;sql&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;PGvq2d&quot; dir=&quot;ltr&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;pre style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 14px 0px;&quot;&gt;&lt;code jsuid=&quot;snuBHc_1d&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; 
    department,
    &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Method 1: SUM with CASE WHEN (Standard across all SQL flavors)&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
    SUM(&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;CASE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;WHEN&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; gender = &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Male&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;THEN&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;ELSE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;END&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; male_count,
    SUM(&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;CASE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;WHEN&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; gender = &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Female&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;THEN&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;ELSE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;END&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; female_count,
    
    &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Method 2: COUNT with CASE WHEN (Alternative syntax)&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
    COUNT(&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;CASE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;WHEN&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; gender = &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Male&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;THEN&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;END&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; alt_male_count,
    COUNT(&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;CASE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;WHEN&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; gender = &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Female&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;THEN&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;END&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; alt_female_count
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;GROUP&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;BY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; department
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;ORDER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;BY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; department;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;iMHp6c&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 3px 0px 0px;&quot;&gt;&lt;div class=&quot;ZIumpf&quot; style=&quot;border-bottom: 0px rgb(32, 33, 36); font-size: 12px; margin: 0px;&quot;&gt;Use code with caution.&lt;/div&gt;&lt;span data-ved=&quot;2ahUKEwiN1rqG7dqXAxWRzTgGHZGwF2IQopQPegYIAAgOEAE&quot; jsaction=&quot;action:&amp;amp;snuBHc_1b|ZUljYd&quot; jsuid=&quot;snuBHc_1c&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwiN1rqG7dqXAxWRzTgGHZGwF2IQh9gSegYIAAgOEAI&quot; jsaction=&quot;&quot; jscontroller=&quot;cXTEid#e0nEwf&quot; jsuid=&quot;snuBHc_1e&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd||GVEHxc=*Q0pj3b|[]--&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;!--TgQPHd|||[[&amp;quot;sql&amp;quot;,&amp;quot;SELECT \n    department,\n    -- Method 1: SUM with CASE WHEN (Standard across all SQL flavors)\n    SUM(CASE WHEN gender \u003d &amp;#39;Male&amp;#39; THEN 1 ELSE 0 END) AS male_count,\n    SUM(CASE WHEN gender \u003d &amp;#39;Female&amp;#39; THEN 1 ELSE 0 END) AS female_count,\n    \n    -- Method 2: COUNT with CASE WHEN (Alternative syntax)\n    COUNT(CASE WHEN gender \u003d &amp;#39;Male&amp;#39; THEN 1 END) AS alt_male_count,\n    COUNT(CASE WHEN gender \u003d &amp;#39;Female&amp;#39; THEN 1 END) AS alt_female_count\nFROM employees\nGROUP BY department\nORDER BY department;\n&amp;quot;,[[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; \n    department,\n    &amp;quot;,0],[&amp;quot;-- Method 1: SUM with CASE WHEN (Standard across all SQL flavors)&amp;quot;,5],[&amp;quot;\n    SUM(&amp;quot;,0],[&amp;quot;CASE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;WHEN&amp;quot;,3],[&amp;quot; gender \u003d &amp;quot;,0],[&amp;quot;&amp;#39;Male&amp;#39;&amp;quot;,4],[&amp;quot; &amp;quot;,0],[&amp;quot;THEN&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot; &amp;quot;,0],[&amp;quot;ELSE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;0&amp;quot;,6],[&amp;quot; &amp;quot;,0],[&amp;quot;END&amp;quot;,3],[&amp;quot;) &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; male_count,\n    SUM(&amp;quot;,0],[&amp;quot;CASE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;WHEN&amp;quot;,3],[&amp;quot; gender \u003d &amp;quot;,0],[&amp;quot;&amp;#39;Female&amp;#39;&amp;quot;,4],[&amp;quot; &amp;quot;,0],[&amp;quot;THEN&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot; &amp;quot;,0],[&amp;quot;ELSE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;0&amp;quot;,6],[&amp;quot; &amp;quot;,0],[&amp;quot;END&amp;quot;,3],[&amp;quot;) &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; female_count,\n    \n    &amp;quot;,0],[&amp;quot;-- Method 2: COUNT with CASE WHEN (Alternative syntax)&amp;quot;,5],[&amp;quot;\n    COUNT(&amp;quot;,0],[&amp;quot;CASE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;WHEN&amp;quot;,3],[&amp;quot; gender \u003d &amp;quot;,0],[&amp;quot;&amp;#39;Male&amp;#39;&amp;quot;,4],[&amp;quot; &amp;quot;,0],[&amp;quot;THEN&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot; &amp;quot;,0],[&amp;quot;END&amp;quot;,3],[&amp;quot;) &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; alt_male_count,\n    COUNT(&amp;quot;,0],[&amp;quot;CASE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;WHEN&amp;quot;,3],[&amp;quot; gender \u003d &amp;quot;,0],[&amp;quot;&amp;#39;Female&amp;#39;&amp;quot;,4],[&amp;quot; &amp;quot;,0],[&amp;quot;THEN&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot; &amp;quot;,0],[&amp;quot;END&amp;quot;,3],[&amp;quot;) &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; alt_female_count\n&amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; employees\n&amp;quot;,0],[&amp;quot;GROUP&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;BY&amp;quot;,3],[&amp;quot; department\n&amp;quot;,0],[&amp;quot;ORDER&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;BY&amp;quot;,3],[&amp;quot; department;\n&amp;quot;,0]]]]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;snuBHc_1i|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;snuBHc_1i&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=snuBHc_1j/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;snuBHc_1j&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;How It Works&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;ul class=&quot;XSq4R KI3fJ&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;wiLEJc#NS0kde&quot; jsuid=&quot;snuBHc_1k&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;&lt;li class=&quot;Z1qcYe&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAB&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;oSLmPe#HokZ0d&quot; jsuid=&quot;snuBHc_1l&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px 0px 12px;&quot;&gt;&lt;span class=&quot;iNqyIf&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;KdQfFc#d5Qebf&quot; jsuid=&quot;snuBHc_1m&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;rQesXe MPyX&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;tP2kf#s32ZS&quot; jsuid=&quot;snuBHc_1n&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;The &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_1o&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;CASE&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; Evaluator:&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt; For every row processed within a department, the &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_1p&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;CASE&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; statement inspects the value of the &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_1q&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;gender&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; column.&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/li&gt;&lt;li class=&quot;Z1qcYe&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAE&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;oSLmPe#HokZ0d&quot; jsuid=&quot;snuBHc_1w&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px 0px 12px;&quot;&gt;&lt;span class=&quot;iNqyIf&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;KdQfFc#d5Qebf&quot; jsuid=&quot;snuBHc_1x&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;rQesXe MPyX&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;tP2kf#s32ZS&quot; jsuid=&quot;snuBHc_1y&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;&lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_1z&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;SUM(CASE ... THEN 1 ELSE 0)&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;:&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt; If the condition matches, it outputs a &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_20&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;1&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;. If it doesn&#39;t match, it outputs a &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_21&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;0&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;. The &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_22&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;SUM()&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; function then tallies up these numbers, effectively calculation a count.&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/li&gt;&lt;li class=&quot;Z1qcYe&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIEBAH&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;oSLmPe#HokZ0d&quot; jsuid=&quot;snuBHc_28&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;iNqyIf&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;KdQfFc#d5Qebf&quot; jsuid=&quot;snuBHc_29&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;rQesXe MPyX&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;tP2kf#s32ZS&quot; jsuid=&quot;snuBHc_2a&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;&lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_2b&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;COUNT(CASE ... THEN 1 END)&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;:&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt; The &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_2c&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;COUNT()&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; function ignores &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_2d&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;NULL&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; values. If the condition matches, it returns a &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_2e&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;1&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;. If it doesn&#39;t match, it implicitly returns &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_2f&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;NULL&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; (since there is no &lt;code class=&quot;KDcb0c&quot; data-complete=&quot;true&quot; data-sae=&quot;&quot; data-sfc-root=&quot;c&quot; dir=&quot;ltr&quot; jsaction=&quot;&quot; jscontroller=&quot;hNviFe#redMub&quot; jsuid=&quot;snuBHc_2g&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;ELSE&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; clause), so it isn&#39;t counted.&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/li&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/ul&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;snuBHc_2m|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;snuBHc_2m&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;hr class=&quot;s6NV4e&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-pl=&quot;|||[]&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;gWGJ0d#iOlsLd&quot; jsuid=&quot;snuBHc_2n&quot; style=&quot;border-bottom: 0px rgb(128, 128, 128); margin: 32px 0px;&quot; /&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;snuBHc_2o|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;snuBHc_2o&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=snuBHc_2p/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;snuBHc_2p&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;Complete Playground Script (Schema + Test Data)&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIExAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;snuBHc_2q&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;You can use this complete script to build the schema, load data, and instantly verify the execution logic:&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;snuBHc_2w|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;snuBHc_2w&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;BpxUDf aiModeUiCodeBlock__Container&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIFBAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;snuBHc_2z,snuBHc_2y&quot; jsaction=&quot;&quot; jscontroller=&quot;Liu6s#lcO7sb&quot; jsuid=&quot;snuBHc_2x&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 4px 0px 0px;&quot;&gt;&lt;div data-processed=&quot;true&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;rq1a2&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 0px;&quot;&gt;&lt;div class=&quot;a2TNg&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;GlO4G&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; margin: 0px;&quot;&gt;sql&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;PGvq2d&quot; dir=&quot;ltr&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;pre style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 14px 0px;&quot;&gt;&lt;code jsuid=&quot;snuBHc_2z&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- 1. CREATE TABLE SCHEMA&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;CREATE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;TABLE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees (
    employee_id INT &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;PRIMARY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;KEY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;,
    employee_name VARCHAR(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
    department VARCHAR(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
    gender VARCHAR(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;)
);

&lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- 2. INSERT SAMPLE DATA&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;INSERT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;INTO&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees (employee_id, employee_name, department, gender) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;VALUES&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Alice&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Engineering&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Female&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Bob&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Sales&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Male&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Charlie&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Engineering&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Male&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Diana&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Engineering&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Female&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Evan&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Sales&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Male&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Fiona&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Marketing&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Female&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;George&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Sales&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Male&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;),
(&lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Hannah&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Marketing&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Female&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;);

&lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- 3. EXECUTE CONDITIONAL AGGREGATION&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;SELECT&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; 
    department,
    SUM(&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;CASE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;WHEN&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; gender = &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Male&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;THEN&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;ELSE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;END&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; male_count,
    SUM(&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;CASE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;WHEN&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; gender = &lt;/span&gt;&lt;span class=&quot;dk3nFb&quot; style=&quot;border-bottom: 0px rgb(24, 128, 56); margin: 0px;&quot;&gt;&#39;Female&#39;&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;THEN&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;ELSE&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;N1kUHb&quot; style=&quot;border-bottom: 0px rgb(180, 89, 8); margin: 0px;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;END&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;AS&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; female_count
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; employees
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;GROUP&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;BY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; department
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;ORDER&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;BY&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; department;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;iMHp6c&quot; data-animation-atomic=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); margin: 3px 0px 0px;&quot;&gt;&lt;div class=&quot;ZIumpf&quot; style=&quot;border-bottom: 0px rgb(32, 33, 36); font-size: 12px; margin: 0px;&quot;&gt;Use code with caution.&lt;/div&gt;&lt;span data-ved=&quot;2ahUKEwiN1rqG7dqXAxWRzTgGHZGwF2IQopQPegYIAAgUEAE&quot; jsaction=&quot;action:&amp;amp;snuBHc_2x|ZUljYd&quot; jsuid=&quot;snuBHc_2y&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwiN1rqG7dqXAxWRzTgGHZGwF2IQh9gSegYIAAgUEAI&quot; jsaction=&quot;&quot; jscontroller=&quot;cXTEid#e0nEwf&quot; jsuid=&quot;snuBHc_30&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd||GVEHxc=*Q0pj3b|[]--&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;!--TgQPHd|||[[&amp;quot;sql&amp;quot;,&amp;quot;-- 1. CREATE TABLE SCHEMA\nCREATE TABLE employees (\n    employee_id INT PRIMARY KEY,\n    employee_name VARCHAR(100),\n    department VARCHAR(50),\n    gender VARCHAR(10)\n);\n\n-- 2. INSERT SAMPLE DATA\nINSERT INTO employees (employee_id, employee_name, department, gender) VALUES\n(1, &amp;#39;Alice&amp;#39;, &amp;#39;Engineering&amp;#39;, &amp;#39;Female&amp;#39;),\n(2, &amp;#39;Bob&amp;#39;, &amp;#39;Sales&amp;#39;, &amp;#39;Male&amp;#39;),\n(3, &amp;#39;Charlie&amp;#39;, &amp;#39;Engineering&amp;#39;, &amp;#39;Male&amp;#39;),\n(4, &amp;#39;Diana&amp;#39;, &amp;#39;Engineering&amp;#39;, &amp;#39;Female&amp;#39;),\n(5, &amp;#39;Evan&amp;#39;, &amp;#39;Sales&amp;#39;, &amp;#39;Male&amp;#39;),\n(6, &amp;#39;Fiona&amp;#39;, &amp;#39;Marketing&amp;#39;, &amp;#39;Female&amp;#39;),\n(7, &amp;#39;George&amp;#39;, &amp;#39;Sales&amp;#39;, &amp;#39;Male&amp;#39;),\n(8, &amp;#39;Hannah&amp;#39;, &amp;#39;Marketing&amp;#39;, &amp;#39;Female&amp;#39;);\n\n-- 3. EXECUTE CONDITIONAL AGGREGATION\nSELECT \n    department,\n    SUM(CASE WHEN gender \u003d &amp;#39;Male&amp;#39; THEN 1 ELSE 0 END) AS male_count,\n    SUM(CASE WHEN gender \u003d &amp;#39;Female&amp;#39; THEN 1 ELSE 0 END) AS female_count\nFROM employees\nGROUP BY department\nORDER BY department;\n&amp;quot;,[[&amp;quot;-- 1. CREATE TABLE SCHEMA&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;CREATE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;TABLE&amp;quot;,3],[&amp;quot; employees (\n    employee_id INT &amp;quot;,0],[&amp;quot;PRIMARY&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;KEY&amp;quot;,3],[&amp;quot;,\n    employee_name VARCHAR(&amp;quot;,0],[&amp;quot;100&amp;quot;,6],[&amp;quot;),\n    department VARCHAR(&amp;quot;,0],[&amp;quot;50&amp;quot;,6],[&amp;quot;),\n    gender VARCHAR(&amp;quot;,0],[&amp;quot;10&amp;quot;,6],[&amp;quot;)\n);\n\n&amp;quot;,0],[&amp;quot;-- 2. INSERT SAMPLE DATA&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;INSERT&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;INTO&amp;quot;,3],[&amp;quot; employees (employee_id, employee_name, department, gender) &amp;quot;,0],[&amp;quot;VALUES&amp;quot;,3],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Alice&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Engineering&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Female&amp;#39;&amp;quot;,4],[&amp;quot;),\n(&amp;quot;,0],[&amp;quot;2&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Bob&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Sales&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Male&amp;#39;&amp;quot;,4],[&amp;quot;),\n(&amp;quot;,0],[&amp;quot;3&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Charlie&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Engineering&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Male&amp;#39;&amp;quot;,4],[&amp;quot;),\n(&amp;quot;,0],[&amp;quot;4&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Diana&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Engineering&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Female&amp;#39;&amp;quot;,4],[&amp;quot;),\n(&amp;quot;,0],[&amp;quot;5&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Evan&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Sales&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Male&amp;#39;&amp;quot;,4],[&amp;quot;),\n(&amp;quot;,0],[&amp;quot;6&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Fiona&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Marketing&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Female&amp;#39;&amp;quot;,4],[&amp;quot;),\n(&amp;quot;,0],[&amp;quot;7&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;George&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Sales&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Male&amp;#39;&amp;quot;,4],[&amp;quot;),\n(&amp;quot;,0],[&amp;quot;8&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Hannah&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Marketing&amp;#39;&amp;quot;,4],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Female&amp;#39;&amp;quot;,4],[&amp;quot;);\n\n&amp;quot;,0],[&amp;quot;-- 3. EXECUTE CONDITIONAL AGGREGATION&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; \n    department,\n    SUM(&amp;quot;,0],[&amp;quot;CASE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;WHEN&amp;quot;,3],[&amp;quot; gender \u003d &amp;quot;,0],[&amp;quot;&amp;#39;Male&amp;#39;&amp;quot;,4],[&amp;quot; &amp;quot;,0],[&amp;quot;THEN&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot; &amp;quot;,0],[&amp;quot;ELSE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;0&amp;quot;,6],[&amp;quot; &amp;quot;,0],[&amp;quot;END&amp;quot;,3],[&amp;quot;) &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; male_count,\n    SUM(&amp;quot;,0],[&amp;quot;CASE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;WHEN&amp;quot;,3],[&amp;quot; gender \u003d &amp;quot;,0],[&amp;quot;&amp;#39;Female&amp;#39;&amp;quot;,4],[&amp;quot; &amp;quot;,0],[&amp;quot;THEN&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot; &amp;quot;,0],[&amp;quot;ELSE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;0&amp;quot;,6],[&amp;quot; &amp;quot;,0],[&amp;quot;END&amp;quot;,3],[&amp;quot;) &amp;quot;,0],[&amp;quot;AS&amp;quot;,3],[&amp;quot; female_count\n&amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; employees\n&amp;quot;,0],[&amp;quot;GROUP&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;BY&amp;quot;,3],[&amp;quot; department\n&amp;quot;,0],[&amp;quot;ORDER&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;BY&amp;quot;,3],[&amp;quot; department;\n&amp;quot;,0]]]]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;snuBHc_34|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;snuBHc_34&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div aria-level=&quot;3&quot; class=&quot;ZLzG0d ncoeY E8xBUb&quot; data-animation-nesting=&quot;&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sae=&quot;&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-attrbind=&quot;aria-level=snuBHc_35/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;snuBHc_35&quot; role=&quot;heading&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 20px; font-weight: 600; margin: 24px 0px 12px;&quot;&gt;Expected Query Output&lt;!--TgQPHd|||[[2,[null,null,null,null,null,null,null,null,null,null,null,null,[351768,null,0]],[],null,1]]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;snuBHc_36|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;snuBHc_36&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;Fv6NCb&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIFhAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwiN1rqG7dqXAxWRzTgGHZGwF2IQ-q4QegYIAAgWEAA&quot; jsaction=&quot;rcuQ6b:&amp;amp;snuBHc_37|npT2md;scroll:&amp;amp;snuBHc_37|ZUljYd&quot; jscontroller=&quot;kbUand#UYOFMe&quot; jsuid=&quot;snuBHc_37&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 4px 0px 12px;&quot;&gt;&lt;table class=&quot;NRefec&quot; data-animation-nesting=&quot;&quot; data-sae=&quot;&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 14px; margin: 0px;&quot;&gt;&lt;tbody style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwiN1rqG7dqXAxWRzTgGHZGwF2IQw4oVegYIAAgWEAE&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;snuBHc_38&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;th class=&quot;BSFG4e&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;qmn2r#iLQbnd&quot; jsuid=&quot;snuBHc_39&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;department&lt;!--TgQPHd|||[]--&gt;&lt;/th&gt;&lt;th class=&quot;BSFG4e&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;qmn2r#iLQbnd&quot; jsuid=&quot;snuBHc_3a&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;male_count&lt;!--TgQPHd|||[]--&gt;&lt;/th&gt;&lt;th class=&quot;BSFG4e&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;qmn2r#iLQbnd&quot; jsuid=&quot;snuBHc_3b&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;female_count&lt;!--TgQPHd|||[]--&gt;&lt;/th&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwiN1rqG7dqXAxWRzTgGHZGwF2IQw4oVegYIAAgWEAI&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;snuBHc_3c&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;snuBHc_3d&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Engineering&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;snuBHc_3e&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;1&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;snuBHc_3f&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;2&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwiN1rqG7dqXAxWRzTgGHZGwF2IQw4oVegYIAAgWEAM&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;snuBHc_3g&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;snuBHc_3h&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Marketing&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;snuBHc_3i&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;0&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;snuBHc_3j&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;2&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;tr class=&quot;l2uqvb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-ved=&quot;2ahUKEwiN1rqG7dqXAxWRzTgGHZGwF2IQw4oVegYIAAgWEAQ&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;snuBHc_3k&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;snuBHc_3l&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;Sales&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;snuBHc_3m&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;3&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;td class=&quot;Vk1lqb&quot; colspan=&quot;undefined&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;v76eI#SQTCXd&quot; jsuid=&quot;snuBHc_3n&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;0&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;!--TgQPHd|||[[1,0,0,3,null,&amp;quot;&amp;quot;]]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;snuBHc_3o|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;snuBHc_3o&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;AHmQrc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIFxAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;LkYPVc#wdvZmf&quot; jsuid=&quot;snuBHc_3p&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIFxAB&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;TDBkbc#Ml18Xb&quot; jsuid=&quot;snuBHc_3q&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;&lt;br /&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;snuBHc_3z|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;snuBHc_3z&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;snuBHc_41|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;snuBHc_41&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;yhAwj&quot; data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;rcuQ6b:&amp;amp;snuBHc_6k|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;snuBHc_6k&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div data-complete=&quot;true&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-subtree=&quot;aimba&quot; jsaction=&quot;&quot; jscontroller=&quot;v48bt#VKyOOd&quot; jsuid=&quot;snuBHc_6l&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;SGF5Lb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;mk5ZW#TASLyc&quot; jsuid=&quot;snuBHc_8&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;SGF5Lb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;mk5ZW#TASLyc&quot; jsuid=&quot;snuBHc_9&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;SGF5Lb&quot; data-complete=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;mk5ZW#TASLyc&quot; jsuid=&quot;snuBHc_a&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;span style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div class=&quot;&quot; data-complete=&quot;true&quot; data-sfc-root=&quot;c&quot; jsaction=&quot;&quot; jscontroller=&quot;zp3Dsd#fP0RJ&quot; jsuid=&quot;snuBHc_b&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/div&gt;&lt;div data-xid=&quot;aQR2uf&quot; jsaction=&quot;aimRestoredThreadVisible:&amp;amp;snuBHc_1|ZUljYd;requestToggleBottomSheet:&amp;amp;snuBHc_1|aXD3Gb&quot; jsuid=&quot;snuBHc_2&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;/div&gt;&lt;div data-complete=&quot;true&quot; data-sfc-inited=&quot;2&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;snuBHc_h,snuBHc_i&quot; jsaction=&quot;rcuQ6b:&amp;amp;snuBHc_g|npT2md&quot; jscontroller=&quot;CAwPlc#Hx4Oqd&quot; jsuid=&quot;snuBHc_g&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-family: &amp;quot;Google Sans&amp;quot;, Arial, sans-serif, &amp;quot;Noto Color Emoji&amp;quot;; font-size: 14px; margin: 0px;&quot;&gt;&lt;!--TgQPHdsnuBHc_1/YOIIaf;snuBHc_1/VWapad|||[{&amp;quot;s&amp;quot;:false,&amp;quot;i&amp;quot;:&amp;quot;snuBHc_1/YOIIaf&amp;quot;},{&amp;quot;s&amp;quot;:null,&amp;quot;i&amp;quot;:&amp;quot;snuBHc_1/VWapad&amp;quot;},156,{&amp;quot;s&amp;quot;:null,&amp;quot;i&amp;quot;:&amp;quot;snuBHc_1/C5DOxd&amp;quot;},[&amp;quot;AimExportActionToastLink&amp;quot;,309275],&amp;quot;\u0026snuBHc_1:bREfu&amp;quot;,false]--&gt;&lt;/div&gt;&lt;!--TgQPHd|snuBHc_1/YOIIaf;snuBHc_1/We76zc;snuBHc_1/C5DOxd;snuBHc_1/LL5gb;snuBHc_1/VWapad||[[null,0,null,0,null,0,[&amp;quot;Write a query to perform a conditional aggregation (count males and\nfemales in each department).&amp;quot;],null,0,[&amp;quot;Write a query to perform a conditional aggregation (count males and\nfemales in each department).&amp;quot;],0]]--&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/3145056141671151266/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/write-query-to-perform-conditional.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/3145056141671151266'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/3145056141671151266'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/write-query-to-perform-conditional.html' title='Write a query to perform a conditional aggregation (count males and females in each department).'/><author><name>sushil kumar</name><uri>http://www.blogger.com/profile/12880032323435050844</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>