<?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-07T19:30:00.172-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>319</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><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><entry><id>tag:blogger.com,1999:blog-5356089030550857026.post-3205320093433545123</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="Azure"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><title type='text'>What is Managed Identity, and why do we use it?</title><content type='html'>&lt;h1&gt;Managed Identity&lt;/h1&gt;
&lt;p&gt;A managed identity is an identity in Microsoft Entra ID that Azure creates and manages for an Azure resource (an App Service, Function App, VM, Container App, AKS workload, and so on). The resource uses it to authenticate to other Azure services without any credentials in your code or config. Azure handles the credential behind the scenes: it creates it, stores it, and rotates it automatically, and you never see or handle the secret.&lt;/p&gt;
&lt;h2&gt;The problem it solves&lt;/h2&gt;
&lt;p&gt;Normally, to call something like Key Vault, SQL, or Storage, your app needs a credential: a connection string, API key, or client secret. That creates a chain of problems:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The credential has to be stored somewhere (config, CI variables, a vault).&lt;/li&gt;
&lt;li&gt;It can leak through source control, logs, or screenshots.&lt;/li&gt;
&lt;li&gt;It expires and needs rotation, which often causes outages when someone forgets.&lt;/li&gt;
&lt;li&gt;To read the secret from Key Vault, you need &lt;em&gt;another&lt;/em&gt; credential (the &quot;secret zero&quot; problem).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Managed identity removes the credential from the picture entirely. The identity &lt;em&gt;is&lt;/em&gt; the resource, and access is granted through RBAC.&lt;/p&gt;
&lt;h2&gt;How it works&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;You enable a managed identity on the resource.&lt;/li&gt;
&lt;li&gt;Azure registers a service principal for it in Entra ID.&lt;/li&gt;
&lt;li&gt;You grant that identity a role on the target resource (e.g., &lt;em&gt;Key Vault Secrets User&lt;/em&gt;, &lt;em&gt;Storage Blob Data Reader&lt;/em&gt;).&lt;/li&gt;
&lt;li&gt;At runtime, your code asks a local token endpoint on the host (the Instance Metadata Service, or the App Service identity endpoint) for an access token for the target resource.&lt;/li&gt;
&lt;li&gt;Azure issues a short-lived token, and your code presents it to the target service, which checks the RBAC assignment.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The token request is only possible from code running on that resource, which is why no secret is needed. The Azure SDKs do all of this for you:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var credential = new DefaultAzureCredential();

var blobs = new BlobServiceClient(
    new Uri(&quot;https://mystorage.blob.core.windows.net&quot;), credential);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;DefaultAzureCredential&lt;/code&gt; uses the managed identity when running in Azure, and falls back to your &lt;code&gt;az login&lt;/code&gt; or Visual Studio sign-in locally, so the same code works in both places.&lt;/p&gt;
&lt;h2&gt;Two types&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;System-assigned&lt;/th&gt;
&lt;th&gt;User-assigned&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Lifecycle&lt;/td&gt;
&lt;td&gt;Tied to the resource; deleted with it&lt;/td&gt;
&lt;td&gt;Standalone resource with its own lifecycle&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sharing&lt;/td&gt;
&lt;td&gt;One resource only&lt;/td&gt;
&lt;td&gt;Can be attached to many resources&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Simple, single-resource scenarios&lt;/td&gt;
&lt;td&gt;Sharing one identity across apps, pre-provisioning access before deployment, or keeping access stable when you recreate resources&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;When using a user-assigned identity, tell the SDK which one to use, since a resource can have several:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var credential = new DefaultAzureCredential(
    new DefaultAzureCredentialOptions { ManagedIdentityClientId = &quot;&amp;lt;client-id&amp;gt;&quot; });
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Setting it up&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# System-assigned
az webapp identity assign --name my-app --resource-group my-rg

# User-assigned
az identity create --name my-identity --resource-group my-rg
az webapp identity assign --name my-app --resource-group my-rg \
  --identities &amp;lt;identity-resource-id&amp;gt;

# Grant access
az role assignment create \
  --assignee &amp;lt;principalId&amp;gt; \
  --role &quot;Storage Blob Data Reader&quot; \
  --scope &amp;lt;storage-account-resource-id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Why use it&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;No secrets to manage:&lt;/strong&gt; nothing to store, leak, or rotate by hand.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Better security posture:&lt;/strong&gt; short-lived tokens, and access governed by RBAC with least privilege and a clear audit trail in Entra ID and Azure Monitor.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Less operational risk:&lt;/strong&gt; no expired-credential outages.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Simpler code and pipelines:&lt;/strong&gt; no secret plumbing between environments.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Free:&lt;/strong&gt; there&#39;s no extra charge for managed identities.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Limitations to know about&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;It only works for &lt;strong&gt;Azure resources&lt;/strong&gt; (and Azure Arc-enabled servers). Code running on-premises or on a laptop can&#39;t use one directly; use &lt;code&gt;DefaultAzureCredential&lt;/code&gt; fallbacks, workload identity federation, or service principals there.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;target service must support Entra authentication&lt;/strong&gt;. Most Azure services do (Key Vault, Storage, Service Bus, SQL, Cosmos DB, Event Hubs), but some third-party services or older features still need keys.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Role assignments take a few minutes to propagate&lt;/strong&gt;, and tokens are cached, so changes aren&#39;t always instant.&lt;/li&gt;
&lt;li&gt;It authenticates the &lt;strong&gt;resource&lt;/strong&gt;, not an end user. If you need per-user access, you need user sign-in (OAuth/OIDC) instead.&lt;/li&gt;
&lt;li&gt;For &lt;strong&gt;Azure SQL&lt;/strong&gt;, you also have to create a database user for the identity (&lt;code&gt;CREATE USER [my-app] FROM EXTERNAL PROVIDER&lt;/code&gt;) and grant it database roles.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Related: workload identity&lt;/h2&gt;
&lt;p&gt;For apps outside Azure (GitHub Actions, Kubernetes on other clouds), &lt;strong&gt;workload identity federation&lt;/strong&gt; gives a similar credential-free experience by trusting tokens from an external identity provider. It&#39;s what the &lt;code&gt;azure/login@v2&lt;/code&gt; OIDC setup in a GitHub Actions workflow uses.&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/3205320093433545123/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/what-is-managed-identity-and-why-do-we.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/3205320093433545123'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/3205320093433545123'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/what-is-managed-identity-and-why-do-we.html' title='What is Managed Identity, 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-8114915845428707538</id><published>2026-10-30T08:35:00.000-07:00</published><updated>2026-10-30T08:35:54.458-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'>What is Routing?</title><content type='html'>&lt;p&gt;&lt;strong&gt;Routing&lt;/strong&gt; is the process of deciding where to send something should go to next, based on where it is trying to reach. A router (or routing system) looks at the destination, checks a set of rules, and forwards the item along the best matching path.&lt;/p&gt;
&lt;h2&gt;A simple analogy&lt;/h2&gt;
&lt;p&gt;Think of a postal sorting office. A letter arrives with an address, and the clerk checks the rules (&quot;anything for this postcode goes to that truck&quot;) and sends it on. No single clerk needs to know about the whole journey, only the next step. Routing in computing works the same way.&lt;/p&gt;
&lt;h2&gt;The two main kinds&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;1. Network routing:&lt;/strong&gt; moving data packets between the networks.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Each packet carries a destination IP address.&lt;/li&gt;
&lt;li&gt;A router checks its &lt;strong&gt;routing table&lt;/strong&gt; and forwards these packet to the next hop, such as another router or the final machine.&lt;/li&gt;
&lt;li&gt;This is how the data crosses your home network, your ISP, and the internet to reach a server.&lt;/li&gt;
&lt;li&gt;If no specific rule matches, a &lt;strong&gt;default route&lt;/strong&gt; sends the packet to a general gateway.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;2. Application (URL) routing:&lt;/strong&gt; moving web requests to the right code.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The destination is a URL such as &#39;&lt;code&gt;/orders/42&#39;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A routing system matches that URL pattern to a specific handler, such as a function, controller, or page.&lt;/li&gt;
&lt;li&gt;This is how the one web application serves many different pages and API endpoints.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Request: GET /orders/42
Rule:    /orders/{id}  -&amp;gt;  OrdersController.Details(id)
Result:  Details(42) runs
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;The core parts&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Part&lt;/th&gt;
&lt;th&gt;What it is&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Destination&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The address, IP or URL, the item is heading to&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Rules / table&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The list of patterns and where each one leads&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Matching&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Picking the best rule, usually the most specific one&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Next hop / handler&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Where the item is sent, a router or a piece of code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Default&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A fallback for anything with no matching rule&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Why we need it&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Scale:&lt;/strong&gt;&amp;nbsp;The senders don&#39;t need to know every path to every destination.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Flexibility:&lt;/strong&gt; you can change where the traffic goes by editing a rule, not every sender.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Control and security:&lt;/strong&gt; you can force traffic through a firewall or block certain paths.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Clean design:&lt;/strong&gt; web URLs stay readable and independent of how the code is organized.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Efficiency:&lt;/strong&gt; traffic takes the best available path.&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/8114915845428707538/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/what-is-routing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/8114915845428707538'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/8114915845428707538'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/what-is-routing.html' title='What is 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-7727662321175818856</id><published>2026-10-30T07:43:00.000-07:00</published><updated>2026-10-30T07:43:00.166-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'>How do you secure an Azure Function?</title><content type='html'>&lt;h1&gt;Securing an Azure Function&lt;/h1&gt;
&lt;p&gt;Securing a function is layered: control who can call it, what it can reach, and where its secrets live. Start with the first three layers, then add the rest as your requirements grow.&lt;/p&gt;
&lt;h2&gt;1. Authenticate and authorize callers (inbound)&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Function keys (the default for HTTP triggers).&lt;/strong&gt; &lt;code&gt;AuthorizationLevel.Function&lt;/code&gt; requires a key in the &lt;code&gt;x-functions-key&lt;/code&gt; header (or &lt;code&gt;?code=&lt;/code&gt;). Keys are simple but they&#39;re shared secrets with no identity attached, so treat them as a minimum, not a full solution. Avoid &lt;code&gt;AuthorizationLevel.Anonymous&lt;/code&gt; unless something else (such as API Management or Easy Auth) is enforcing access in front of it. Note that &lt;code&gt;Admin&lt;/code&gt; level uses the master key, which grants access to everything, so never share it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;App Service Authentication (&quot;Easy Auth&quot;) with Microsoft Entra ID.&lt;/strong&gt; This is the recommended approach for user- or service-facing APIs. The platform validates tokens before your code runs. Enable it under &lt;strong&gt;Settings → Authentication&lt;/strong&gt; and set unauthenticated requests to return 401:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az webapp auth update --name my-func-app --resource-group my-rg \
  --enabled true --action Return401
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You then add an Entra ID identity provider (via the portal or &lt;code&gt;az webapp auth microsoft update&lt;/code&gt;) with your app registration. For finer control, check roles or scopes in code from the validated claims.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;API Management in front.&lt;/strong&gt; Put APIM in front of the function to get JWT validation, rate limiting, IP filtering, and subscription keys, and then restrict the function so it only accepts traffic from APIM.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Webhooks from third parties&lt;/strong&gt; (Stripe, GitHub): verify the provider&#39;s signature header inside your function rather than relying only on a key.&lt;/p&gt;
&lt;h2&gt;2. Restrict the network&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Access restrictions:&lt;/strong&gt; allow only specific IP ranges, service tags, or VNets (e.g., only your APIM or Front Door).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Private endpoints:&lt;/strong&gt; make the function reachable only from inside your VNet (Premium, Flex Consumption, or Dedicated plans).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Front Door or Application Gateway with WAF:&lt;/strong&gt; adds DDoS and OWASP protection, and you can lock the function to accept traffic only from them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;VNet integration (outbound):&lt;/strong&gt; lets the function reach private resources like databases and Key Vault over the VNet, so those can have their public access turned off.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;3. Use managed identity instead of connection strings (outbound)&lt;/h2&gt;
&lt;p&gt;Give the function a managed identity and grant it RBAC roles on the resources it needs. This removes stored credentials entirely.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az functionapp identity assign --name my-func-app --resource-group my-rg
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// In the isolated worker, no keys required
var client = new BlobServiceClient(
    new Uri(&quot;https://mystorage.blob.core.windows.net&quot;),
    new DefaultAzureCredential());
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Triggers and bindings can use identity-based connections too. For example, with Service Bus you set &lt;code&gt;ServiceBusConnection__fullyQualifiedNamespace&lt;/code&gt; instead of a connection string, and grant the identity the &lt;em&gt;Azure Service Bus Data Receiver&lt;/em&gt; role. The same pattern works for the function&#39;s own host storage account (&lt;code&gt;AzureWebJobsStorage__accountName&lt;/code&gt;), which is worth doing so you can disable shared key access on that account.&lt;/p&gt;
&lt;h2&gt;4. Protect secrets&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Store remaining secrets in &lt;strong&gt;Key Vault&lt;/strong&gt; and use &lt;strong&gt;Key Vault references&lt;/strong&gt; in app settings: &lt;code&gt;@Microsoft.KeyVault(VaultName=my-vault;SecretName=MySecret)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Never commit secrets to source control or put them in &lt;code&gt;local.settings.json&lt;/code&gt; files that get checked in (that file is for local development only).&lt;/li&gt;
&lt;li&gt;Rotate function keys periodically, and use per-client keys or host keys rather than distributing the default key broadly.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;5. Harden the transport and the platform&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;HTTPS only:&lt;/strong&gt; &lt;code&gt;az functionapp update --set httpsOnly=true&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Minimum TLS version 1.2&lt;/strong&gt;, and disable FTP/FTPS deployment where you can (&lt;code&gt;--ftps-state Disabled&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Disable SCM basic auth&lt;/strong&gt; and deploy using Entra identities or federated credentials from CI/CD.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CORS:&lt;/strong&gt; list only the exact origins that need browser access, and never use &lt;code&gt;*&lt;/code&gt; for authenticated APIs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Keep the runtime current:&lt;/strong&gt; use a supported .NET and Functions runtime version, and update dependencies.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;6. Code-level hygiene&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Validate and sanitize all inputs, including queue and blob payloads, not just HTTP.&lt;/li&gt;
&lt;li&gt;Don&#39;t return stack traces or internal details in error responses.&lt;/li&gt;
&lt;li&gt;Apply least privilege. A function that only reads a queue shouldn&#39;t have write access to the storage account.&lt;/li&gt;
&lt;li&gt;Avoid logging sensitive data (tokens, PII, secrets).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;7. Monitor and detect&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Enable &lt;strong&gt;Application Insights&lt;/strong&gt; and diagnostic logs to Log Analytics.&lt;/li&gt;
&lt;li&gt;Turn on &lt;strong&gt;Microsoft Defender for Cloud&lt;/strong&gt; (Defender for App Service covers Function Apps) for threat detection and recommendations.&lt;/li&gt;
&lt;li&gt;Alert on spikes in 401/403 responses, unusual invocation counts, and failed Key Vault access.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;A sensible baseline&lt;/h2&gt;
&lt;p&gt;For a typical HTTP-triggered API:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Enable Easy Auth with Entra ID (return 401 for unauthenticated calls).&lt;/li&gt;
&lt;li&gt;Use a managed identity with least-privilege RBAC for everything the function touches.&lt;/li&gt;
&lt;li&gt;Put APIM or Front Door in front and restrict inbound access to it.&lt;/li&gt;
&lt;li&gt;Store leftover secrets in Key Vault, enforce HTTPS and TLS 1.2+, and disable FTP and basic auth.&lt;/li&gt;
&lt;li&gt;Send logs to Application Insights and enable Defender for Cloud.&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/7727662321175818856/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/how-do-you-secure-azure-function.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/7727662321175818856'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/7727662321175818856'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/how-do-you-secure-azure-function.html' title='How do you secure an Azure 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-6258403366316495028</id><published>2026-10-29T20:30:00.000-07:00</published><updated>2026-10-29T20:30:00.166-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'>Find customers who have not made any purchase.</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;xo5dhd_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;xo5dhd_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;2ahUKEwiopIDa7NqXAxUG2jgGHSqFI9gQ3KYQegYIAAgIEAE&quot; data-xid=&quot;VpUvz&quot; dir=&quot;ltr&quot; jsaction=&quot;cC6SSe:&amp;amp;xo5dhd_7|mNzCb;&quot; jscontroller=&quot;Aoijq#INwBm&quot; jsname=&quot;KFl8ub&quot; jsuid=&quot;xo5dhd_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;xo5dhd_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 customers who have never made a purchase, you need to identify rows in your &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;xo5dhd_q&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;customers&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; table that have no corresponding matching records in your &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;xo5dhd_r&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;orders&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;xo5dhd_s&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;purchases&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;) table.&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;xo5dhd_y&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;Here are the &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;xo5dhd_z&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;three most efficient SQL methods&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt; to achieve this, along with a complete schema script to test it yourself.&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;xo5dhd_15|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_15&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;xo5dhd_16&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;xo5dhd_17|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_17&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=xo5dhd_18/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;xo5dhd_18&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 &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;xo5dhd_19&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;LEFT JOIN&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; (Recommended &amp;amp; Most Common)&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;CAAIDxAA&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;xo5dhd_1a&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;This method joins both tables and filters out any rows where the order details come back empty (&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;xo5dhd_1b&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;).&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;xo5dhd_1h|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_1h&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;CAAIEBAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;xo5dhd_1k,xo5dhd_1j&quot; jsaction=&quot;&quot; jscontroller=&quot;Liu6s#lcO7sb&quot; jsuid=&quot;xo5dhd_1i&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;xo5dhd_1k&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; c.customer_id, c.customer_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; customers c
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;LEFT&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; orders o &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; c.customer_id = o.customer_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; o.order_id &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;IS&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;/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;2ahUKEwiopIDa7NqXAxUG2jgGHSqFI9gQopQPegYIAAgQEAE&quot; jsaction=&quot;action:&amp;amp;xo5dhd_1i|ZUljYd&quot; jsuid=&quot;xo5dhd_1j&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;2ahUKEwiopIDa7NqXAxUG2jgGHSqFI9gQh9gSegYIAAgQEAI&quot; jsaction=&quot;&quot; jscontroller=&quot;cXTEid#e0nEwf&quot; jsuid=&quot;xo5dhd_1l&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 c.customer_id, c.customer_name\nFROM customers c\nLEFT JOIN orders o ON c.customer_id \u003d o.customer_id\nWHERE o.order_id IS NULL;\n&amp;quot;,[[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; c.customer_id, c.customer_name\n&amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; customers c\n&amp;quot;,0],[&amp;quot;LEFT&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;JOIN&amp;quot;,3],[&amp;quot; orders o &amp;quot;,0],[&amp;quot;ON&amp;quot;,3],[&amp;quot; c.customer_id \u003d o.customer_id\n&amp;quot;,0],[&amp;quot;WHERE&amp;quot;,3],[&amp;quot; o.order_id &amp;quot;,0],[&amp;quot;IS&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;NULL&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;xo5dhd_1p|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_1p&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=xo5dhd_1q/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;xo5dhd_1q&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 &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;xo5dhd_1r&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;NOT EXISTS&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; (Highly Efficient for Large Datasets)&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;CAAIEhAA&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;xo5dhd_1s&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;This method checks every customer record and returns it only if a subquery searching the orders table yields zero results.&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;xo5dhd_1y|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_1y&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;CAAIExAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;xo5dhd_21,xo5dhd_20&quot; jsaction=&quot;&quot; jscontroller=&quot;Liu6s#lcO7sb&quot; jsuid=&quot;xo5dhd_1z&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;xo5dhd_21&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; customer_id, customer_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; customers c
&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; &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;NOT&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;EXISTS&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; &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;FROM&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt; orders o 
    &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; o.customer_id = c.customer_id
);
&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;2ahUKEwiopIDa7NqXAxUG2jgGHSqFI9gQopQPegYIAAgTEAE&quot; jsaction=&quot;action:&amp;amp;xo5dhd_1z|ZUljYd&quot; jsuid=&quot;xo5dhd_20&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;2ahUKEwiopIDa7NqXAxUG2jgGHSqFI9gQh9gSegYIAAgTEAI&quot; jsaction=&quot;&quot; jscontroller=&quot;cXTEid#e0nEwf&quot; jsuid=&quot;xo5dhd_22&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 customer_id, customer_name\nFROM customers c\nWHERE NOT EXISTS (\n    SELECT 1 \n    FROM orders o \n    WHERE o.customer_id \u003d c.customer_id\n);\n&amp;quot;,[[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; customer_id, customer_name\n&amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; customers c\n&amp;quot;,0],[&amp;quot;WHERE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;NOT&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;EXISTS&amp;quot;,3],[&amp;quot; (\n    &amp;quot;,0],[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot; \n    &amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; orders o \n    &amp;quot;,0],[&amp;quot;WHERE&amp;quot;,3],[&amp;quot; o.customer_id \u003d c.customer_id\n);\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;xo5dhd_26|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_26&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=xo5dhd_27/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;xo5dhd_27&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 3: 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;xo5dhd_28&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;NOT IN&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;div class=&quot;n6owBd awi2gc&quot; data-complete=&quot;true&quot; data-hveid=&quot;CAAIFRAA&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;xo5dhd_29&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;A simple approach that reads like plain English. &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;xo5dhd_2a&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;(Warning: This method will fail to return results if 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;xo5dhd_2b&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;orders.customer_id&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; column contains any &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;xo5dhd_2c&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).&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;xo5dhd_2i|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_2i&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;CAAIFhAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;xo5dhd_2l,xo5dhd_2k&quot; jsaction=&quot;&quot; jscontroller=&quot;Liu6s#lcO7sb&quot; jsuid=&quot;xo5dhd_2j&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;xo5dhd_2l&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; customer_id, customer_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; customers
&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; customer_id &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;NOT&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;IN&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; customer_id 
    &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; orders 
    &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; customer_id &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;IS&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;NOT&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;/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;2ahUKEwiopIDa7NqXAxUG2jgGHSqFI9gQopQPegYIAAgWEAE&quot; jsaction=&quot;action:&amp;amp;xo5dhd_2j|ZUljYd&quot; jsuid=&quot;xo5dhd_2k&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;2ahUKEwiopIDa7NqXAxUG2jgGHSqFI9gQh9gSegYIAAgWEAI&quot; jsaction=&quot;&quot; jscontroller=&quot;cXTEid#e0nEwf&quot; jsuid=&quot;xo5dhd_2m&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 customer_id, customer_name\nFROM customers\nWHERE customer_id NOT IN (\n    SELECT customer_id \n    FROM orders \n    WHERE customer_id IS NOT NULL\n);\n&amp;quot;,[[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; customer_id, customer_name\n&amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; customers\n&amp;quot;,0],[&amp;quot;WHERE&amp;quot;,3],[&amp;quot; customer_id &amp;quot;,0],[&amp;quot;NOT&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;IN&amp;quot;,3],[&amp;quot; (\n    &amp;quot;,0],[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; customer_id \n    &amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; orders \n    &amp;quot;,0],[&amp;quot;WHERE&amp;quot;,3],[&amp;quot; customer_id &amp;quot;,0],[&amp;quot;IS&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;NOT&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;NULL&amp;quot;,3],[&amp;quot;\n);\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;xo5dhd_2q|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_2q&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;xo5dhd_2r&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;xo5dhd_2s|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_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=xo5dhd_2t/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;xo5dhd_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;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;CAAIGRAA&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;xo5dhd_2u&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 see the queries in action:&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;xo5dhd_30|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_30&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;CAAIGhAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;xo5dhd_33,xo5dhd_32&quot; jsaction=&quot;&quot; jscontroller=&quot;Liu6s#lcO7sb&quot; jsuid=&quot;xo5dhd_31&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;xo5dhd_33&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 Tables&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; customers (
    customer_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;,
    customer_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;)
);

&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; orders (
    order_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;,
    customer_id INT,
    order_date &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;DATE&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;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; (customer_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; customers(customer_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;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; customers (customer_id, customer_name) &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;John Doe&#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;-- Has placed an 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;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;Jane 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;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Has NOT placed an 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;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 Johnson&#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;-- Has placed an 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;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;Alice Williams&#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;-- Has NOT placed an 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;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; orders (order_id, customer_id, order_date) &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;101&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;2026-10-25&#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;102&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;2026-10-26&#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;103&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;2026-10-27&#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. Run the selection (Will return Jane Smith and Alice Williams)&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; c.customer_id, c.customer_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; customers c
&lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;LEFT&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; orders o &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; c.customer_id = o.customer_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; o.order_id &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;IS&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;/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;2ahUKEwiopIDa7NqXAxUG2jgGHSqFI9gQopQPegYIAAgaEAE&quot; jsaction=&quot;action:&amp;amp;xo5dhd_31|ZUljYd&quot; jsuid=&quot;xo5dhd_32&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;2ahUKEwiopIDa7NqXAxUG2jgGHSqFI9gQh9gSegYIAAgaEAI&quot; jsaction=&quot;&quot; jscontroller=&quot;cXTEid#e0nEwf&quot; jsuid=&quot;xo5dhd_34&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 Tables\nCREATE TABLE customers (\n    customer_id INT PRIMARY KEY,\n    customer_name VARCHAR(100)\n);\n\nCREATE TABLE orders (\n    order_id INT PRIMARY KEY,\n    customer_id INT,\n    order_date DATE,\n    FOREIGN KEY (customer_id) REFERENCES customers(customer_id)\n);\n\n-- 2. Insert Sample Data\nINSERT INTO customers (customer_id, customer_name) VALUES\n(1, &amp;#39;John Doe&amp;#39;),      -- Has placed an order\n(2, &amp;#39;Jane Smith&amp;#39;),    -- Has NOT placed an order\n(3, &amp;#39;Bob Johnson&amp;#39;),   -- Has placed an order\n(4, &amp;#39;Alice Williams&amp;#39;);-- Has NOT placed an order\n\nINSERT INTO orders (order_id, customer_id, order_date) VALUES\n(101, 1, &amp;#39;2026-10-25&amp;#39;),\n(102, 3, &amp;#39;2026-10-26&amp;#39;),\n(103, 1, &amp;#39;2026-10-27&amp;#39;);\n\n-- 3. Run the selection (Will return Jane Smith and Alice Williams)\nSELECT c.customer_id, c.customer_name\nFROM customers c\nLEFT JOIN orders o ON c.customer_id \u003d o.customer_id\nWHERE o.order_id IS NULL;\n&amp;quot;,[[&amp;quot;-- 1. Create Tables&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; customers (\n    customer_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    customer_name VARCHAR(&amp;quot;,0],[&amp;quot;100&amp;quot;,6],[&amp;quot;)\n);\n\n&amp;quot;,0],[&amp;quot;CREATE&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;TABLE&amp;quot;,3],[&amp;quot; orders (\n    order_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    customer_id INT,\n    order_date &amp;quot;,0],[&amp;quot;DATE&amp;quot;,3],[&amp;quot;,\n    &amp;quot;,0],[&amp;quot;FOREIGN&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;KEY&amp;quot;,3],[&amp;quot; (customer_id) &amp;quot;,0],[&amp;quot;REFERENCES&amp;quot;,3],[&amp;quot; customers(customer_id)\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; customers (customer_id, customer_name) &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;John Doe&amp;#39;&amp;quot;,4],[&amp;quot;),      &amp;quot;,0],[&amp;quot;-- Has placed an order&amp;quot;,5],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;2&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Jane Smith&amp;#39;&amp;quot;,4],[&amp;quot;),    &amp;quot;,0],[&amp;quot;-- Has NOT placed an order&amp;quot;,5],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;3&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Bob Johnson&amp;#39;&amp;quot;,4],[&amp;quot;),   &amp;quot;,0],[&amp;quot;-- Has placed an order&amp;quot;,5],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;4&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;Alice Williams&amp;#39;&amp;quot;,4],[&amp;quot;);&amp;quot;,0],[&amp;quot;-- Has NOT placed an order&amp;quot;,5],[&amp;quot;\n\n&amp;quot;,0],[&amp;quot;INSERT&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;INTO&amp;quot;,3],[&amp;quot; orders (order_id, customer_id, order_date) &amp;quot;,0],[&amp;quot;VALUES&amp;quot;,3],[&amp;quot;\n(&amp;quot;,0],[&amp;quot;101&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;2026-10-25&amp;#39;&amp;quot;,4],[&amp;quot;),\n(&amp;quot;,0],[&amp;quot;102&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;3&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;2026-10-26&amp;#39;&amp;quot;,4],[&amp;quot;),\n(&amp;quot;,0],[&amp;quot;103&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;1&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;2026-10-27&amp;#39;&amp;quot;,4],[&amp;quot;);\n\n&amp;quot;,0],[&amp;quot;-- 3. Run the selection (Will return Jane Smith and Alice Williams)&amp;quot;,5],[&amp;quot;\n&amp;quot;,0],[&amp;quot;SELECT&amp;quot;,3],[&amp;quot; c.customer_id, c.customer_name\n&amp;quot;,0],[&amp;quot;FROM&amp;quot;,3],[&amp;quot; customers c\n&amp;quot;,0],[&amp;quot;LEFT&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;JOIN&amp;quot;,3],[&amp;quot; orders o &amp;quot;,0],[&amp;quot;ON&amp;quot;,3],[&amp;quot; c.customer_id \u003d o.customer_id\n&amp;quot;,0],[&amp;quot;WHERE&amp;quot;,3],[&amp;quot; o.order_id &amp;quot;,0],[&amp;quot;IS&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;NULL&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;xo5dhd_38|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_38&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=xo5dhd_39/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;xo5dhd_39&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;xo5dhd_3a|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_3a&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;CAAIHBAA&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;2ahUKEwiopIDa7NqXAxUG2jgGHSqFI9gQ-q4QegYIAAgcEAA&quot; jsaction=&quot;rcuQ6b:&amp;amp;xo5dhd_3b|npT2md;scroll:&amp;amp;xo5dhd_3b|ZUljYd&quot; jscontroller=&quot;kbUand#UYOFMe&quot; jsuid=&quot;xo5dhd_3b&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;2ahUKEwiopIDa7NqXAxUG2jgGHSqFI9gQw4oVegYIAAgcEAE&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;xo5dhd_3c&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;xo5dhd_3d&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;customer_id&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;xo5dhd_3e&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;customer_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;2ahUKEwiopIDa7NqXAxUG2jgGHSqFI9gQw4oVegYIAAgcEAI&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;xo5dhd_3f&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;xo5dhd_3g&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;2&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;xo5dhd_3h&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Jane 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;2ahUKEwiopIDa7NqXAxUG2jgGHSqFI9gQw4oVegYIAAgcEAM&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;xo5dhd_3i&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;xo5dhd_3j&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;4&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;xo5dhd_3k&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;Alice Williams&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;!--TgQPHd|||[[1,0,0,2,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;xo5dhd_3l|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_3l&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;CAAIHRAA&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;xo5dhd_3m&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;CAAIHRAB&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;xo5dhd_3n&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;xo5dhd_3w|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_3w&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;xo5dhd_3y|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_3y&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;xo5dhd_6b|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;xo5dhd_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;xo5dhd_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-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;xo5dhd_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;xo5dhd_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;xo5dhd_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;xo5dhd_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;xo5dhd_1|ZUljYd;requestToggleBottomSheet:&amp;amp;xo5dhd_1|aXD3Gb&quot; jsuid=&quot;xo5dhd_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;xo5dhd_h,xo5dhd_i&quot; jsaction=&quot;rcuQ6b:&amp;amp;xo5dhd_g|npT2md&quot; jscontroller=&quot;CAwPlc#Hx4Oqd&quot; jsuid=&quot;xo5dhd_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;!--TgQPHdxo5dhd_1/VWapad;xo5dhd_1/YOIIaf|||[{&amp;quot;s&amp;quot;:false,&amp;quot;i&amp;quot;:&amp;quot;xo5dhd_1/YOIIaf&amp;quot;},{&amp;quot;s&amp;quot;:null,&amp;quot;i&amp;quot;:&amp;quot;xo5dhd_1/VWapad&amp;quot;},156,{&amp;quot;s&amp;quot;:null,&amp;quot;i&amp;quot;:&amp;quot;xo5dhd_1/C5DOxd&amp;quot;},[&amp;quot;AimExportActionToastLink&amp;quot;,309275],&amp;quot;\u0026xo5dhd_1:bREfu&amp;quot;,false]--&gt;&lt;/div&gt;&lt;!--TgQPHd|xo5dhd_1/VWapad;xo5dhd_1/C5DOxd;xo5dhd_1/We76zc;xo5dhd_1/YOIIaf;xo5dhd_1/LL5gb||[[null,0,null,0,null,0,[&amp;quot;Find customers who have not made any purchase.&amp;quot;],null,0,[&amp;quot;Find customers who have not made any purchase.&amp;quot;],0]]--&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/6258403366316495028/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/find-customers-who-have-not-made-any.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/6258403366316495028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/6258403366316495028'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/find-customers-who-have-not-made-any.html' title='Find customers who have not made any purchase.'/><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-5761341347450833441</id><published>2026-10-28T20:30:00.000-07:00</published><updated>2026-10-28T20:30:00.179-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 Azure Key Vault, and how do you use it from a .NET application?</title><content type='html'>&lt;h1&gt;Azure Key Vault&lt;/h1&gt;
&lt;p&gt;Azure Key Vault is a managed service for storing and controlling access to sensitive material, so secrets don&#39;t end up in source code, config files, or CI variables. It handles three kinds of objects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Secrets:&lt;/strong&gt; arbitrary small values such as connection strings, API keys, and passwords.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Keys:&lt;/strong&gt; cryptographic keys (RSA, EC) used for signing, encryption, and wrapping. Operations run inside the vault, so private key material never leaves it (with HSM-backed keys, never leaves the HSM).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Certificates:&lt;/strong&gt; TLS/SSL certificates with lifecycle management, including auto-renewal with supported CAs.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Tiers:&lt;/strong&gt; Standard (software-protected keys), Premium (HSM-backed keys), and &lt;strong&gt;Managed HSM&lt;/strong&gt; (a dedicated, single-tenant HSM pool for the strictest compliance needs).&lt;/p&gt;
&lt;h2&gt;Key features&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Access control:&lt;/strong&gt; Azure RBAC is the recommended model (access policies are the legacy model). Common roles are &lt;em&gt;Key Vault Secrets User&lt;/em&gt; (read secrets), &lt;em&gt;Key Vault Secrets Officer&lt;/em&gt; (manage them), &lt;em&gt;Key Vault Crypto User&lt;/em&gt;, and &lt;em&gt;Key Vault Administrator&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Soft delete and purge protection:&lt;/strong&gt; deleted items can be recovered during a retention period, and purge protection prevents permanent deletion until it ends.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Versioning:&lt;/strong&gt; every secret update creates a new version, so you can roll back or rotate gracefully.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Auditing:&lt;/strong&gt; logs go to Azure Monitor / Log Analytics.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Network security:&lt;/strong&gt; firewall rules and private endpoints.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Events:&lt;/strong&gt; Event Grid notifications for things like a secret nearing expiry.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;The best practice: no credentials to reach the vault&lt;/h2&gt;
&lt;p&gt;Your app authenticates to Key Vault with a &lt;strong&gt;managed identity&lt;/strong&gt;, so you don&#39;t need a secret to get your secrets. &lt;code&gt;DefaultAzureCredential&lt;/code&gt; uses the managed identity when running in Azure, and falls back to your &lt;code&gt;az login&lt;/code&gt; or Visual Studio sign-in locally.&lt;/p&gt;
&lt;h3&gt;1. Create the vault and grant access&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;az keyvault create --name my-unique-vault --resource-group my-rg \
  --location centralindia --enable-rbac-authorization true

az keyvault secret set --vault-name my-unique-vault \
  --name &quot;ConnectionStrings--Default&quot; --value &quot;Server=...;Password=...&quot;

# Enable a system-assigned identity on your App Service
az webapp identity assign --name my-unique-app-name --resource-group my-rg

# Let that identity read secrets
az role assignment create \
  --role &quot;Key Vault Secrets User&quot; \
  --assignee &amp;lt;principalId-from-previous-command&amp;gt; \
  --scope $(az keyvault show --name my-unique-vault --query id -o tsv)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For local development, give your own user the same role on the vault, and make sure you&#39;re signed in with &lt;code&gt;az login&lt;/code&gt; or Visual Studio.&lt;/p&gt;
&lt;h3&gt;2. Option A: load secrets into &lt;code&gt;IConfiguration&lt;/code&gt; (most common)&lt;/h3&gt;
&lt;p&gt;Install the packages:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Azure.Identity
dotnet add package Azure.Extensions.AspNetCore.Configuration.Secrets
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Azure.Identity;

var builder = WebApplication.CreateBuilder(args);

builder.Configuration.AddAzureKeyVault(
    new Uri(&quot;https://my-unique-vault.vault.azure.net/&quot;),
    new DefaultAzureCredential());

var app = builder.Build();

// Reads the Key Vault secret &quot;ConnectionStrings--Default&quot;
var cs = builder.Configuration.GetConnectionString(&quot;Default&quot;);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Key Vault secret names can&#39;t contain &lt;code&gt;:&lt;/code&gt;, so use &lt;code&gt;--&lt;/code&gt; instead. &lt;code&gt;ConnectionStrings--Default&lt;/code&gt; maps to &lt;code&gt;ConnectionStrings:Default&lt;/code&gt;. Secrets are loaded at startup, and the provider can refresh periodically if you set a &lt;code&gt;ReloadInterval&lt;/code&gt; in &lt;code&gt;AzureKeyVaultConfigurationOptions&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;3. Option B: call Key Vault directly with the SDK&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package Azure.Security.KeyVault.Secrets
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using Azure.Identity;
using Azure.Security.KeyVault.Secrets;

var client = new SecretClient(
    new Uri(&quot;https://my-unique-vault.vault.azure.net/&quot;),
    new DefaultAzureCredential());

KeyVaultSecret secret = await client.GetSecretAsync(&quot;StripeApiKey&quot;);
string apiKey = secret.Value;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For keys and certificates, use &lt;code&gt;Azure.Security.KeyVault.Keys&lt;/code&gt; (&lt;code&gt;KeyClient&lt;/code&gt; and &lt;code&gt;CryptographyClient&lt;/code&gt; for encrypt/sign operations) and &lt;code&gt;Azure.Security.KeyVault.Certificates&lt;/code&gt; (&lt;code&gt;CertificateClient&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Register the client once via dependency injection rather than creating it per request:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;builder.Services.AddSingleton(_ =&amp;gt; new SecretClient(
    new Uri(&quot;https://my-unique-vault.vault.azure.net/&quot;),
    new DefaultAzureCredential()));
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;4. Option C: Key Vault references (no code changes)&lt;/h3&gt;
&lt;p&gt;In App Service or Azure Functions, set an app setting whose value is a reference:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@Microsoft.KeyVault(SecretUri=https://my-unique-vault.vault.azure.net/secrets/StripeApiKey/)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@Microsoft.KeyVault(VaultName=my-unique-vault;SecretName=StripeApiKey)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The platform resolves it using the app&#39;s managed identity and injects the value as an ordinary environment variable. Your .NET code just reads &lt;code&gt;IConfiguration&lt;/code&gt; as usual. It&#39;s the simplest approach when you&#39;re already on App Service or Functions, and leaving the version off means the app picks up newer secret versions automatically.&lt;/p&gt;
&lt;h2&gt;Practical tips&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Cache secrets&lt;/strong&gt; instead of fetching them on every request. Key Vault has per-vault throttling limits, and each call adds latency.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Prefer RBAC and least privilege:&lt;/strong&gt; &lt;em&gt;Secrets User&lt;/em&gt; for apps, with write roles reserved for pipelines or admins.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use one vault per app and environment&lt;/strong&gt; (dev/test/prod) so access can be scoped tightly.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rotate secrets:&lt;/strong&gt; set expiry dates, subscribe to the &lt;code&gt;SecretNearExpiry&lt;/code&gt; event, and have your app tolerate version changes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Don&#39;t log secret values&lt;/strong&gt;, and avoid putting the vault URI in places where it matters if exposed (the URI isn&#39;t secret, but access control should be what protects it).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related uses:&lt;/strong&gt; ASP.NET Core Data Protection keys can be protected with a Key Vault key, and Entra ID app credentials can be certificate-based using Key Vault certificates.&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/5761341347450833441/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/what-is-azure-key-vault-and-how-do-you.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/5761341347450833441'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/5761341347450833441'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/what-is-azure-key-vault-and-how-do-you.html' title='What is Azure Key Vault, and how do you use it from a .NET application?'/><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-8063204127378247061</id><published>2026-10-28T20:30:00.000-07:00</published><updated>2026-10-28T20:30:00.179-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 find gaps in a sequence of numbers (missing IDs).</title><content type='html'>&lt;h1&gt;Finding Gaps in a Sequence (Missing IDs) in SQL&lt;/h1&gt;
&lt;h2&gt;Table&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE Orders (
    OrderId INT PRIMARY KEY,
    Customer VARCHAR(100)
);

INSERT INTO Orders (OrderId, Customer) VALUES
(1, &#39;A&#39;), (2, &#39;B&#39;), (3, &#39;C&#39;),
(6, &#39;D&#39;), (7, &#39;E&#39;),
(10, &#39;F&#39;),
(14, &#39;G&#39;), (15, &#39;H&#39;);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Missing IDs: 4, 5, 8, 9, 11, 12, 13.&lt;/p&gt;
&lt;h2&gt;Query 1: gap ranges (start and end of each gap)&lt;/h2&gt;
&lt;p&gt;Uses &lt;code&gt;LEAD&lt;/code&gt; to compare each ID with the next one.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH NextId AS (
    SELECT
        OrderId,
        LEAD(OrderId) OVER (ORDER BY OrderId) AS NextOrderId
    FROM Orders
)
SELECT
    OrderId + 1         AS GapStart,
    NextOrderId - 1     AS GapEnd,
    NextOrderId - OrderId - 1 AS MissingCount
FROM NextId
WHERE NextOrderId - OrderId &amp;gt; 1
ORDER BY GapStart;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Result&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&quot;right&quot;&gt;GapStart&lt;/th&gt;
&lt;th align=&quot;right&quot;&gt;GapEnd&lt;/th&gt;
&lt;th align=&quot;right&quot;&gt;MissingCount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;4&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;5&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;8&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;9&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;11&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;13&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;This is the fastest and most compact approach. It reads the table once and returns one row per gap.&lt;/p&gt;
&lt;h2&gt;Query 2: every missing ID listed individually&lt;/h2&gt;
&lt;h3&gt;SQL Server / Azure SQL (recursive CTE, no numbers table needed)&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH Bounds AS (
    SELECT MIN(OrderId) AS MinId, MAX(OrderId) AS MaxId FROM Orders
),
AllIds AS (
    SELECT MinId AS Id, MaxId FROM Bounds
    UNION ALL
    SELECT Id + 1, MaxId FROM AllIds WHERE Id &amp;lt; MaxId
)
SELECT a.Id AS MissingId
FROM AllIds a
LEFT JOIN Orders o ON o.OrderId = a.Id
WHERE o.OrderId IS NULL
ORDER BY a.Id
OPTION (MAXRECURSION 0);
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;SQL Server 2022 / Azure SQL (&lt;code&gt;GENERATE_SERIES&lt;/code&gt;)&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT s.value AS MissingId
FROM GENERATE_SERIES(
        (SELECT MIN(OrderId) FROM Orders),
        (SELECT MAX(OrderId) FROM Orders)) s
LEFT JOIN Orders o ON o.OrderId = s.value
WHERE o.OrderId IS NULL
ORDER BY s.value;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;PostgreSQL&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT g AS missing_id
FROM generate_series(
        (SELECT MIN(order_id) FROM orders),
        (SELECT MAX(order_id) FROM orders)) AS g
LEFT JOIN orders o ON o.order_id = g
WHERE o.order_id IS NULL
ORDER BY g;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Result&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&quot;right&quot;&gt;MissingId&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;11&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;13&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Query 3: gaps and islands (alternative using ROW_NUMBER)&lt;/h2&gt;
&lt;p&gt;Shows the present ranges; the gaps are the spaces between them.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH Islands AS (
    SELECT
        MIN(OrderId) AS IslandStart,
        MAX(OrderId) AS IslandEnd
    FROM (
        SELECT OrderId,
               OrderId - ROW_NUMBER() OVER (ORDER BY OrderId) AS grp
        FROM Orders
    ) t
    GROUP BY grp
)
SELECT IslandStart, IslandEnd
FROM Islands
ORDER BY IslandStart;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Result&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&quot;right&quot;&gt;IslandStart&lt;/th&gt;
&lt;th align=&quot;right&quot;&gt;IslandEnd&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;1&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;6&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;10&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;14&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;15&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Query 4: gaps without window functions (older databases)&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT
    o.OrderId + 1 AS GapStart,
    (SELECT MIN(o2.OrderId) FROM Orders o2 WHERE o2.OrderId &amp;gt; o.OrderId) - 1 AS GapEnd
FROM Orders o
WHERE NOT EXISTS (SELECT 1 FROM Orders o2 WHERE o2.OrderId = o.OrderId + 1)
  AND o.OrderId &amp;lt; (SELECT MAX(OrderId) FROM Orders)
ORDER BY GapStart;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Slower, since it runs subqueries per row, but it works on any database.&lt;/p&gt;
&lt;h2&gt;Query 5: gaps per group (for example, per customer or per year)&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH NextId AS (
    SELECT
        Region,
        InvoiceNo,
        LEAD(InvoiceNo) OVER (PARTITION BY Region ORDER BY InvoiceNo) AS NextInvoiceNo
    FROM Invoices
)
SELECT Region,
       InvoiceNo + 1     AS GapStart,
       NextInvoiceNo - 1 AS GapEnd
FROM NextId
WHERE NextInvoiceNo - InvoiceNo &amp;gt; 1
ORDER BY Region, GapStart;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;PARTITION BY&lt;/code&gt; restarts the check for each group, which is what you want when every group has its own numbering.&lt;/p&gt;
&lt;h2&gt;Query 6: check whether the sequence starts at 1&lt;/h2&gt;
&lt;p&gt;The queries above only find gaps between existing IDs. To catch missing IDs at the beginning:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT 1 AS GapStart, MIN(OrderId) - 1 AS GapEnd
FROM Orders
HAVING MIN(OrderId) &amp;gt; 1;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For missing IDs after the last one, you need an expected maximum from somewhere else (a counter, a config value, or a parent table), since the table itself can&#39;t know.&lt;/p&gt;
&lt;h2&gt;Details&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;LEAD&lt;/code&gt; approach (Query 1)&lt;/strong&gt; is the best default: one pass, one row per gap, easy to read.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Listing each missing ID (Query 2)&lt;/strong&gt; needs a generated range of numbers. The recursive CTE works anywhere; &lt;code&gt;GENERATE_SERIES&lt;/code&gt; is simpler where available (SQL Server 2022+, Azure SQL, PostgreSQL).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Recursion limit:&lt;/strong&gt; SQL Server stops at 100 levels by default, so use &lt;code&gt;OPTION (MAXRECURSION 0)&lt;/code&gt; for large ranges. For millions of IDs, use a numbers (tally) table instead.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Duplicates:&lt;/strong&gt; if the column isn&#39;t unique, add &lt;code&gt;SELECT DISTINCT&lt;/code&gt; in the first CTE, otherwise &lt;code&gt;LEAD&lt;/code&gt; returns the same value and hides gaps.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Identity columns&lt;/strong&gt; create gaps naturally (rolled-back inserts, deletes, failed transactions), so gaps there are usually normal. Gaps matter for things like invoice numbers, where auditors expect a continuous sequence.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sequence start and end:&lt;/strong&gt; decide whether leading and trailing gaps count (Query 6).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Supporting index&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Usually the primary key already covers this. For a non-key column:
CREATE INDEX IX_Orders_OrderId ON Orders (OrderId);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An ordered index lets &lt;code&gt;LEAD&lt;/code&gt; and &lt;code&gt;ROW_NUMBER&lt;/code&gt; read the rows without a sort.&lt;/p&gt;
&lt;h2&gt;Compatibility&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;LEAD&lt;/code&gt; and &lt;code&gt;ROW_NUMBER&lt;/code&gt; work in Azure SQL, SQL Server 2012+, PostgreSQL, MySQL 8.0+, Oracle, and SQLite 3.25+. &lt;code&gt;GENERATE_SERIES&lt;/code&gt; requires SQL Server 2022+ or PostgreSQL. In MySQL, use a recursive CTE with &lt;code&gt;WITH RECURSIVE&lt;/code&gt; for the full list of missing IDs.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/8063204127378247061/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/write-query-to-find-gaps-in-sequence-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/8063204127378247061'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/8063204127378247061'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/write-query-to-find-gaps-in-sequence-of.html' title='Write a query to find gaps in a sequence of numbers (missing IDs).'/><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-882185370367241028</id><published>2026-10-27T20:30:00.000-07:00</published><updated>2026-10-27T20:30:00.125-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'>Recursive query to find the full reporting chain for each employee.</title><content type='html'>&lt;h1&gt;Full Reporting Chain per Employee (Recursive CTE)&lt;/h1&gt;
&lt;h2&gt;Table&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE Employees (
    EmployeeId INT PRIMARY KEY,
    Name       VARCHAR(100),
    ManagerId  INT NULL REFERENCES Employees(EmployeeId)
);

INSERT INTO Employees (EmployeeId, Name, ManagerId) VALUES
(1, &#39;Anita&#39;,  NULL),   -- CEO
(2, &#39;Rahul&#39;,  1),
(3, &#39;Priya&#39;,  1),
(4, &#39;Vikram&#39;, 2),
(5, &#39;Sneha&#39;,  2),
(6, &#39;Arjun&#39;,  4);
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Approach&lt;/h2&gt;
&lt;p&gt;A recursive CTE has two parts:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Anchor member:&lt;/strong&gt; the starting rows. Each employee paired with their direct manager.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Recursive member:&lt;/strong&gt; joins the previous result to &lt;code&gt;Employees&lt;/code&gt; to climb one level higher, repeating until it reaches a row with no manager.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Query 1: every employee with all their managers (one row per level)&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH ReportingChain AS (
    -- Anchor: each employee and their direct manager
    SELECT
        e.EmployeeId,
        e.Name          AS EmployeeName,
        e.ManagerId     AS CurrentManagerId,
        1               AS Level
    FROM Employees e
    WHERE e.ManagerId IS NOT NULL

    UNION ALL

    -- Recursive: move up to the manager&#39;s manager
    SELECT
        rc.EmployeeId,
        rc.EmployeeName,
        m.ManagerId,
        rc.Level + 1
    FROM ReportingChain rc
    JOIN Employees m ON m.EmployeeId = rc.CurrentManagerId
    WHERE m.ManagerId IS NOT NULL
)
SELECT
    rc.EmployeeId,
    rc.EmployeeName,
    rc.Level,
    mgr.EmployeeId AS ManagerId,
    mgr.Name       AS ManagerName
FROM ReportingChain rc
JOIN Employees mgr ON mgr.EmployeeId = rc.CurrentManagerId
ORDER BY rc.EmployeeId, rc.Level;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Result (excerpt)&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;EmployeeName&lt;/th&gt;
&lt;th align=&quot;right&quot;&gt;Level&lt;/th&gt;
&lt;th&gt;ManagerName&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Arjun&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;1&lt;/td&gt;
&lt;td&gt;Vikram&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Arjun&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;2&lt;/td&gt;
&lt;td&gt;Rahul&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Arjun&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;3&lt;/td&gt;
&lt;td&gt;Anita&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Vikram&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;1&lt;/td&gt;
&lt;td&gt;Rahul&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Vikram&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;2&lt;/td&gt;
&lt;td&gt;Anita&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sneha&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;1&lt;/td&gt;
&lt;td&gt;Rahul&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sneha&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;2&lt;/td&gt;
&lt;td&gt;Anita&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Query 2: the chain as a single string per employee&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH Chain AS (
    -- Anchor: start at every employee
    SELECT
        EmployeeId,
        Name,
        ManagerId,
        CAST(Name AS VARCHAR(1000)) AS ChainPath,
        0 AS Depth
    FROM Employees

    UNION ALL

    -- Recursive: append the next manager up
    SELECT
        c.EmployeeId,
        c.Name,
        m.ManagerId,
        CAST(c.ChainPath + &#39; -&amp;gt; &#39; + m.Name AS VARCHAR(1000)),
        c.Depth + 1
    FROM Chain c
    JOIN Employees m ON m.EmployeeId = c.ManagerId
)
SELECT EmployeeId, Name, ChainPath, Depth AS LevelsAboveEmployee
FROM (
    SELECT *,
           ROW_NUMBER() OVER (PARTITION BY EmployeeId ORDER BY Depth DESC) AS rn
    FROM Chain
) x
WHERE rn = 1
ORDER BY EmployeeId;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Result&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;ChainPath&lt;/th&gt;
&lt;th align=&quot;right&quot;&gt;LevelsAboveEmployee&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Anita&lt;/td&gt;
&lt;td&gt;Anita&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Rahul&lt;/td&gt;
&lt;td&gt;Rahul -&amp;gt; Anita&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Priya&lt;/td&gt;
&lt;td&gt;Priya -&amp;gt; Anita&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Vikram&lt;/td&gt;
&lt;td&gt;Vikram -&amp;gt; Rahul -&amp;gt; Anita&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sneha&lt;/td&gt;
&lt;td&gt;Sneha -&amp;gt; Rahul -&amp;gt; Anita&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Arjun&lt;/td&gt;
&lt;td&gt;Arjun -&amp;gt; Vikram -&amp;gt; Rahul -&amp;gt; Anita&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The final &lt;code&gt;ROW_NUMBER() ... ORDER BY Depth DESC&lt;/code&gt; keeps only the longest (complete) path per employee.&lt;/p&gt;
&lt;h2&gt;Query 3: top-down hierarchy (the org tree from the CEO)&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH OrgTree AS (
    SELECT EmployeeId, Name, ManagerId,
           0 AS Level,
           CAST(Name AS VARCHAR(1000)) AS Path
    FROM Employees
    WHERE ManagerId IS NULL

    UNION ALL

    SELECT e.EmployeeId, e.Name, e.ManagerId,
           t.Level + 1,
           CAST(t.Path + &#39; &amp;gt; &#39; + e.Name AS VARCHAR(1000))
    FROM Employees e
    JOIN OrgTree t ON e.ManagerId = t.EmployeeId
)
SELECT REPLICATE(&#39;    &#39;, Level) + Name AS OrgChart, Level, Path
FROM OrgTree
ORDER BY Path;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Result:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Anita
    Priya
    Rahul
        Sneha
        Vikram
            Arjun
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Query 4: all direct and indirect reports of one manager&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;DECLARE @ManagerId INT = 2;

WITH Reports AS (
    SELECT EmployeeId, Name, ManagerId, 1 AS Level
    FROM Employees
    WHERE ManagerId = @ManagerId

    UNION ALL

    SELECT e.EmployeeId, e.Name, e.ManagerId, r.Level + 1
    FROM Employees e
    JOIN Reports r ON e.ManagerId = r.EmployeeId
)
SELECT * FROM Reports ORDER BY Level, Name;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Details&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;UNION ALL&lt;/code&gt;&lt;/strong&gt; is required between the anchor and recursive members. Use &lt;code&gt;UNION&lt;/code&gt; only in dialects that need it for cycle handling, and expect it to be slower.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Recursion limit:&lt;/strong&gt; SQL Server stops at 100 levels by default. Raise or remove it with &lt;code&gt;OPTION (MAXRECURSION 0)&lt;/code&gt; (0 = unlimited), but only after guarding against cycles.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cycles:&lt;/strong&gt; if bad data makes someone their own ancestor (A manages B, B manages A), the recursion never ends. Guard with a depth cap or a path check:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- In the recursive member:
WHERE c.ChainPath NOT LIKE &#39;%&#39; + m.Name + &#39;%&#39;   -- simple guard, or
  AND c.Depth &amp;lt; 20                               -- depth cap
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For a precise check, track visited IDs in a delimited string (&lt;code&gt;&#39;/1/2/4/&#39;&lt;/code&gt;) and test &lt;code&gt;CHARINDEX(&#39;/&#39; + CAST(m.EmployeeId AS VARCHAR) + &#39;/&#39;, c.IdPath) = 0&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Multiple roots:&lt;/strong&gt; if several rows have &lt;code&gt;ManagerId IS NULL&lt;/code&gt;, Query 3 returns each as a separate tree.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Employees with no manager&lt;/strong&gt; (the CEO) have no rows in Query 1, but appear with depth 0 in Query 2.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data type:&lt;/strong&gt; make the path column wide enough (&lt;code&gt;VARCHAR(1000)&lt;/code&gt;). The anchor&#39;s type fixes the column type, and a too-short anchor causes truncation errors in the recursive member.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;PostgreSQL / MySQL version&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH RECURSIVE chain AS (
    SELECT employee_id, name, manager_id,
           name::text AS chain_path,
           0 AS depth
    FROM employees

    UNION ALL

    SELECT c.employee_id, c.name, m.manager_id,
           c.chain_path || &#39; -&amp;gt; &#39; || m.name,
           c.depth + 1
    FROM chain c
    JOIN employees m ON m.employee_id = c.manager_id
)
SELECT DISTINCT ON (employee_id) employee_id, name, chain_path, depth
FROM chain
ORDER BY employee_id, depth DESC;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notes: the keyword is &lt;code&gt;WITH RECURSIVE&lt;/code&gt;. Use &lt;code&gt;CONCAT()&lt;/code&gt; instead of &lt;code&gt;||&lt;/code&gt; in MySQL, and replace &lt;code&gt;DISTINCT ON&lt;/code&gt; with the &lt;code&gt;ROW_NUMBER()&lt;/code&gt; pattern from Query 2. Oracle supports both recursive CTEs and &lt;code&gt;CONNECT BY PRIOR&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Supporting index&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE INDEX IX_Employees_ManagerId ON Employees (ManagerId) INCLUDE (Name);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each recursive step joins on &lt;code&gt;ManagerId&lt;/code&gt; or &lt;code&gt;EmployeeId&lt;/code&gt;. The primary key covers the second, and this index covers the first.&lt;/p&gt;
&lt;h2&gt;Alternative: &lt;code&gt;hierarchyid&lt;/code&gt; (SQL Server)&lt;/h2&gt;
&lt;p&gt;For large, read-heavy hierarchies, the &lt;code&gt;hierarchyid&lt;/code&gt; type stores the path in the column and avoids recursion at query time:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;ALTER TABLE Employees ADD OrgNode hierarchyid;
-- Ancestors of an employee:
SELECT * FROM Employees e
WHERE @targetNode.IsDescendantOf(e.OrgNode) = 1;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It requires maintaining the node values on every insert or reparent, so use it when hierarchy reads far outnumber writes.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/882185370367241028/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/recursive-query-to-find-full-reporting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/882185370367241028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/882185370367241028'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/recursive-query-to-find-full-reporting.html' title='Recursive query to find the full reporting chain for each employee.'/><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-2545067301146322855</id><published>2026-10-27T20:30:00.000-07:00</published><updated>2026-10-27T20:30:00.125-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 Azure Service Bus, and how does it work?</title><content type='html'>&lt;h1&gt;Azure Service Bus&lt;/h1&gt;
&lt;p&gt;Azure Service Bus is a fully managed enterprise message broker. It sits between applications and lets them communicate asynchronously: a sender puts a message on the broker and moves on, and a receiver picks it up whenever it&#39;s ready. This decouples services in time (they don&#39;t need to be online together), in load (a burst of messages is buffered), and in technology (any client that speaks AMQP, or uses the SDKs, can participate).&lt;/p&gt;
&lt;h2&gt;Core concepts&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Namespace:&lt;/strong&gt; the container for your messaging entities, with its own endpoint, pricing tier, and network and security settings.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Queue:&lt;/strong&gt; point-to-point messaging. Many senders can send, but each message is delivered to exactly one receiver (competing consumers share the load).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Topic and subscriptions:&lt;/strong&gt; publish/subscribe. A sender publishes to a topic, and each subscription gets its own copy of every matching message. Each subscription behaves like a virtual queue.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rules and filters:&lt;/strong&gt; on a subscription, you can filter messages by properties (e.g., &lt;code&gt;region = &#39;EU&#39;&lt;/code&gt;) so each subscriber only receives what it cares about.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Message:&lt;/strong&gt; a body plus system properties (MessageId, SessionId, TimeToLive, etc.) and custom application properties.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;How it works&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Send:&lt;/strong&gt; the producer sends a message to a queue or topic. The broker stores it durably (replicated storage) before acknowledging.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Store:&lt;/strong&gt; the message waits until a consumer retrieves it or its time-to-live expires.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Receive:&lt;/strong&gt; the consumer receives the message using one of two modes:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Peek-lock (default):&lt;/strong&gt; the message is locked, not deleted. The consumer processes it, then &lt;strong&gt;completes&lt;/strong&gt; it (removed). If processing fails, it can &lt;strong&gt;abandon&lt;/strong&gt; it (becomes available again) or &lt;strong&gt;dead-letter&lt;/strong&gt; it. If the lock expires without a response, the message returns to the queue.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Receive-and-delete:&lt;/strong&gt; the message is removed immediately on receipt. Faster, but it&#39;s lost if the consumer crashes mid-processing.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Retry and dead-letter:&lt;/strong&gt; each message has a delivery count. Once it exceeds &lt;code&gt;MaxDeliveryCount&lt;/code&gt; (default 10), it moves to the &lt;strong&gt;dead-letter queue (DLQ)&lt;/strong&gt;, a sub-queue where you can inspect and reprocess poison messages.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Key features&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Delivery guarantees:&lt;/strong&gt; at-least-once by default, so consumers should be idempotent. &lt;strong&gt;Duplicate detection&lt;/strong&gt; can discard resends within a time window.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sessions:&lt;/strong&gt; group related messages with a SessionId to get FIFO ordering within the group and exclusive processing by one consumer at a time.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scheduled messages:&lt;/strong&gt; enqueue now, deliver at a future time.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transactions:&lt;/strong&gt; group operations (e.g., complete one message and send another) atomically.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Auto-forwarding:&lt;/strong&gt; chain queues or subscriptions together.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Security:&lt;/strong&gt; Microsoft Entra ID with RBAC (preferred over shared access keys), private endpoints, and customer-managed keys.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Resilience:&lt;/strong&gt; availability zones, plus Geo-Replication or Geo-Disaster Recovery on the Premium tier.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Tiers&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Standard:&lt;/strong&gt; pay-as-you-go, shared infrastructure, messages up to 256 KB.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Premium:&lt;/strong&gt; dedicated resources (messaging units), predictable performance, VNet and private endpoint support, and larger messages (up to 100 MB).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Quick C# example&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;await using var client = new ServiceBusClient(
    &quot;mynamespace.servicebus.windows.net&quot;, new DefaultAzureCredential());

// Send
ServiceBusSender sender = client.CreateSender(&quot;orders&quot;);
await sender.SendMessageAsync(new ServiceBusMessage(&quot;Order #1234 placed&quot;));

// Receive
ServiceBusReceiver receiver = client.CreateReceiver(&quot;orders&quot;);
ServiceBusReceivedMessage msg = await receiver.ReceiveMessageAsync();
Console.WriteLine(msg.Body.ToString());
await receiver.CompleteMessageAsync(msg);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For real workloads, &lt;code&gt;ServiceBusProcessor&lt;/code&gt; handles concurrency, lock renewal, and error handling for you, and Azure Functions has a Service Bus trigger that does the same with almost no code.&lt;/p&gt;
&lt;h2&gt;When to use it&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Order processing, payments, and other workflows where messages must not be lost&lt;/li&gt;
&lt;li&gt;Decoupling microservices and smoothing out traffic spikes (load leveling)&lt;/li&gt;
&lt;li&gt;Fan-out of events to multiple downstream systems via topics&lt;/li&gt;
&lt;li&gt;Ordered processing per customer or entity using sessions&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Service Bus vs. related services&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Service Bus&lt;/th&gt;
&lt;th&gt;Storage Queues&lt;/th&gt;
&lt;th&gt;Event Grid&lt;/th&gt;
&lt;th&gt;Event Hubs&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;Enterprise broker (queues, topics)&lt;/td&gt;
&lt;td&gt;Simple queue&lt;/td&gt;
&lt;td&gt;Event routing (reactive)&lt;/td&gt;
&lt;td&gt;High-throughput event streaming&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ordering, sessions, transactions&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;td&gt;Ordering per partition&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Business messages and commands&lt;/td&gt;
&lt;td&gt;Basic, cheap queuing&lt;/td&gt;
&lt;td&gt;&quot;Something happened&quot; notifications&lt;/td&gt;
&lt;td&gt;Telemetry and log ingestion&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Rule of thumb: use &lt;strong&gt;Service Bus&lt;/strong&gt; when a message represents work that must be processed reliably, &lt;strong&gt;Event Grid&lt;/strong&gt; for lightweight notifications, and &lt;strong&gt;Event Hubs&lt;/strong&gt; for massive streams of telemetry.&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/2545067301146322855/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/what-is-azure-service-bus-and-how-does.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/2545067301146322855'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/2545067301146322855'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/what-is-azure-service-bus-and-how-does.html' title='What is Azure Service Bus, and how does it work?'/><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-6982502076306957687</id><published>2026-10-27T20:30:00.000-07:00</published><updated>2026-10-27T20:30:00.125-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'>Find the longest consecutive streak of daily logins for each user.</title><content type='html'>&lt;h1&gt;Longest Consecutive Daily Login Streak per User (SQL)&lt;/h1&gt;
&lt;h2&gt;Table&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE UserLogins (
    UserId    INT,
    LoginTime DATETIME2
);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Sample data:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;INSERT INTO UserLogins (UserId, LoginTime) VALUES
(1, &#39;2026-10-01 08:15&#39;), (1, &#39;2026-10-01 19:40&#39;),
(1, &#39;2026-10-02 09:00&#39;), (1, &#39;2026-10-03 10:30&#39;),
(1, &#39;2026-10-06 07:45&#39;), (1, &#39;2026-10-07 08:05&#39;),
(2, &#39;2026-10-01 12:00&#39;), (2, &#39;2026-10-03 12:00&#39;), (2, &#39;2026-10-04 12:00&#39;),
(3, &#39;2026-10-05 22:10&#39;);
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Approach: gaps and islands&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Reduce logins to &lt;strong&gt;one row per user per day&lt;/strong&gt; (users can log in many times a day).&lt;/li&gt;
&lt;li&gt;Number each user&#39;s days with &lt;code&gt;ROW_NUMBER()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Subtract that number from the date. For consecutive days the result is constant, so it identifies the streak (&quot;island&quot;).&lt;/li&gt;
&lt;li&gt;Group by that value, count days per streak, and take the maximum per user.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Query (SQL Server / Azure SQL)&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH DistinctDays AS (
    SELECT DISTINCT
        UserId,
        CAST(LoginTime AS DATE) AS LoginDate
    FROM UserLogins
),
Numbered AS (
    SELECT
        UserId,
        LoginDate,
        DATEADD(DAY,
                -ROW_NUMBER() OVER (PARTITION BY UserId ORDER BY LoginDate),
                LoginDate) AS StreakKey
    FROM DistinctDays
),
Streaks AS (
    SELECT
        UserId,
        MIN(LoginDate) AS StreakStart,
        MAX(LoginDate) AS StreakEnd,
        COUNT(*)       AS StreakDays
    FROM Numbered
    GROUP BY UserId, StreakKey
),
Ranked AS (
    SELECT *,
           ROW_NUMBER() OVER (
               PARTITION BY UserId
               ORDER BY StreakDays DESC, StreakStart DESC
           ) AS rn
    FROM Streaks
)
SELECT UserId, StreakStart, StreakEnd, StreakDays AS LongestStreak
FROM Ranked
WHERE rn = 1
ORDER BY UserId;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Result&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&quot;right&quot;&gt;UserId&lt;/th&gt;
&lt;th&gt;StreakStart&lt;/th&gt;
&lt;th&gt;StreakEnd&lt;/th&gt;
&lt;th align=&quot;right&quot;&gt;LongestStreak&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;1&lt;/td&gt;
&lt;td&gt;2026-10-01&lt;/td&gt;
&lt;td&gt;2026-10-03&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;2&lt;/td&gt;
&lt;td&gt;2026-10-03&lt;/td&gt;
&lt;td&gt;2026-10-04&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;right&quot;&gt;3&lt;/td&gt;
&lt;td&gt;2026-10-05&lt;/td&gt;
&lt;td&gt;2026-10-05&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;How the streak key works&lt;/h2&gt;
&lt;p&gt;For user 1, after de-duplicating days:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;LoginDate&lt;/th&gt;
&lt;th align=&quot;right&quot;&gt;ROW_NUMBER&lt;/th&gt;
&lt;th&gt;LoginDate - ROW_NUMBER (StreakKey)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2026-10-01&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;1&lt;/td&gt;
&lt;td&gt;2026-09-30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2026-10-02&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;2&lt;/td&gt;
&lt;td&gt;2026-09-30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2026-10-03&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;3&lt;/td&gt;
&lt;td&gt;2026-09-30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2026-10-06&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;4&lt;/td&gt;
&lt;td&gt;2026-10-02&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2026-10-07&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;5&lt;/td&gt;
&lt;td&gt;2026-10-02&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Consecutive days share the same key. A gap changes it, starting a new island.&lt;/p&gt;
&lt;h2&gt;Details&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;De-duplicate first.&lt;/strong&gt; Without &lt;code&gt;DISTINCT&lt;/code&gt; on the date, multiple logins in a day break the row numbering and the streak math.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;CAST(... AS DATE)&lt;/code&gt;&lt;/strong&gt; removes the time portion. If your timestamps are stored in UTC and &quot;day&quot; means the user&#39;s local day, convert the time zone first (&lt;code&gt;AT TIME ZONE&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ties:&lt;/strong&gt; if a user has two streaks of equal length, the query returns the most recent one (&lt;code&gt;StreakStart DESC&lt;/code&gt;). Change the order to &lt;code&gt;ASC&lt;/code&gt; for the earliest, or use &lt;code&gt;RANK()&lt;/code&gt; to return all tied streaks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Users with no logins&lt;/strong&gt; don&#39;t appear. Left join from a Users table if you need them with a 0.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Only the length, not the dates:&lt;/strong&gt; replace the last two CTEs with&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT UserId, MAX(StreakDays) AS LongestStreak
FROM Streaks
GROUP BY UserId;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Variation: current streak (ending today)&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH DistinctDays AS (
    SELECT DISTINCT UserId, CAST(LoginTime AS DATE) AS LoginDate
    FROM UserLogins
),
Numbered AS (
    SELECT UserId, LoginDate,
           DATEADD(DAY, -ROW_NUMBER() OVER (PARTITION BY UserId ORDER BY LoginDate), LoginDate) AS StreakKey
    FROM DistinctDays
),
Streaks AS (
    SELECT UserId, MIN(LoginDate) AS StreakStart, MAX(LoginDate) AS StreakEnd, COUNT(*) AS StreakDays
    FROM Numbered
    GROUP BY UserId, StreakKey
)
SELECT UserId, StreakStart, StreakEnd, StreakDays AS CurrentStreak
FROM Streaks
WHERE StreakEnd &amp;gt;= DATEADD(DAY, -1, CAST(GETDATE() AS DATE));  -- logged in today or yesterday
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Alternative: LAG-based&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH DistinctDays AS (
    SELECT DISTINCT UserId, CAST(LoginTime AS DATE) AS LoginDate
    FROM UserLogins
),
Flagged AS (
    SELECT UserId, LoginDate,
           CASE WHEN DATEDIFF(DAY,
                    LAG(LoginDate) OVER (PARTITION BY UserId ORDER BY LoginDate),
                    LoginDate) = 1
                THEN 0 ELSE 1 END AS IsNewStreak
    FROM DistinctDays
),
Grouped AS (
    SELECT UserId, LoginDate,
           SUM(IsNewStreak) OVER (
               PARTITION BY UserId ORDER BY LoginDate
               ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
           ) AS StreakId
    FROM Flagged
)
SELECT UserId, StreakId,
       MIN(LoginDate) AS StreakStart, MAX(LoginDate) AS StreakEnd, COUNT(*) AS StreakDays
FROM Grouped
GROUP BY UserId, StreakId;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This flags a new streak whenever the previous login day isn&#39;t exactly one day earlier, then a running sum assigns a streak ID. It&#39;s easier to read and extends to other rules (for example, allowing a one-day gap).&lt;/p&gt;
&lt;h2&gt;PostgreSQL version&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH days AS (
    SELECT DISTINCT user_id, login_time::date AS login_date
    FROM user_logins
),
numbered AS (
    SELECT user_id, login_date,
           login_date - (ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY login_date))::int AS streak_key
    FROM days
),
streaks AS (
    SELECT user_id, MIN(login_date) AS streak_start, MAX(login_date) AS streak_end, COUNT(*) AS streak_days
    FROM numbered
    GROUP BY user_id, streak_key
)
SELECT DISTINCT ON (user_id) user_id, streak_start, streak_end, streak_days
FROM streaks
ORDER BY user_id, streak_days DESC, streak_start DESC;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Supporting index&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE INDEX IX_UserLogins_User_Time
ON UserLogins (UserId, LoginTime);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This lets the database read each user&#39;s logins already ordered. For very large tables, consider a pre-aggregated daily table (&lt;code&gt;UserId&lt;/code&gt;, &lt;code&gt;LoginDate&lt;/code&gt;) so the &lt;code&gt;DISTINCT&lt;/code&gt; step isn&#39;t repeated on every run.&lt;/p&gt;
&lt;h2&gt;Compatibility&lt;/h2&gt;
&lt;p&gt;Window functions (&lt;code&gt;ROW_NUMBER&lt;/code&gt;, &lt;code&gt;LAG&lt;/code&gt;) work in Azure SQL, SQL Server 2012+, PostgreSQL, MySQL 8.0+, Oracle, and SQLite 3.25+. Only the date arithmetic changes by dialect: &lt;code&gt;DATEADD&lt;/code&gt; / &lt;code&gt;DATEDIFF&lt;/code&gt; in SQL Server, date subtraction in PostgreSQL, &lt;code&gt;DATE_SUB&lt;/code&gt; / &lt;code&gt;DATEDIFF&lt;/code&gt; in MySQL.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/6982502076306957687/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/find-longest-consecutive-streak-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/6982502076306957687'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/6982502076306957687'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/find-longest-consecutive-streak-of.html' title='Find the longest consecutive streak of daily logins for each user.'/><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-5634986291259401733</id><published>2026-10-27T11:40:32.024-07:00</published><updated>2026-10-27T11:40:32.024-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 rank employees based on salary.</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;QrODie_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;QrODie_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;2ahUKEwiZ8bbs69qXAxX8yTgGHaCGB-gQ3KYQegYIAAgIEAE&quot; data-xid=&quot;VpUvz&quot; dir=&quot;ltr&quot; jsaction=&quot;cC6SSe:&amp;amp;QrODie_7|mNzCb;&quot; jscontroller=&quot;Aoijq#INwBm&quot; jsname=&quot;KFl8ub&quot; jsuid=&quot;QrODie_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;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;QrODie_o|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;QrODie_o&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=QrODie_p/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;QrODie_p&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;&lt;span data-subtree=&quot;aimfl&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;Employee Salary Ranking&lt;/span&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;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;QrODie_r&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-size: 16px; margin: 12px 0px 16px;&quot;&gt;Here is the complete, production-ready SQL script. It sets up the table structure, populates it with realistic sample data (including identical salaries to demonstrate tie-handling), and runs the ranking 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;QrODie_s|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;QrODie_s&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;CAAIDRAA&quot; data-processed=&quot;true&quot; data-sfc-cp=&quot;&quot; data-sfc-root=&quot;c&quot; data-wiz-uids=&quot;QrODie_v,QrODie_u&quot; jsaction=&quot;&quot; jscontroller=&quot;Liu6s#lcO7sb&quot; jsuid=&quot;QrODie_t&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;QrODie_v&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;) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;NOT&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;,
    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;) &lt;/span&gt;&lt;span class=&quot;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;NOT&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;,
    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;uiJ0Tc&quot; style=&quot;border-bottom: 0px rgb(147, 52, 230); margin: 0px;&quot;&gt;NOT&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;-- 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;-- Includes identical salaries in &#39;Sales&#39; and &#39;Engineering&#39; to showcase tie-handling&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;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;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;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 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;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 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;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;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 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;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 Clark&#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;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 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 RANKING 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_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;-- Unique row index per record&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
    ROW_NUMBER() &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; row_num,
    
    &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Traditional rank (Skips ranks after ties: 1, 2, 2, 2, 5...)&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
    RANK() &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; standard_rank,
    
    &lt;/span&gt;&lt;span class=&quot;ojrtQ&quot; style=&quot;border-bottom: 0px rgb(128, 134, 139); margin: 0px;&quot;&gt;-- Dense rank (No gaps in ranking order: 1, 2, 2, 2, 3...)&lt;/span&gt;&lt;span class=&quot;undefined&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;
    DENSE_RANK() &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; dense_rank
&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;2ahUKEwiZ8bbs69qXAxX8yTgGHaCGB-gQopQPegYIAAgNEAE&quot; jsaction=&quot;action:&amp;amp;QrODie_t|ZUljYd&quot; jsuid=&quot;QrODie_u&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;2ahUKEwiZ8bbs69qXAxX8yTgGHaCGB-gQh9gSegYIAAgNEAI&quot; jsaction=&quot;&quot; jscontroller=&quot;cXTEid#e0nEwf&quot; jsuid=&quot;QrODie_w&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) NOT NULL,\n    department VARCHAR(50) NOT NULL,\n    salary DECIMAL(10, 2) NOT NULL\n);\n\n-- 2. INSERT SAMPLE DATA\n-- Includes identical salaries in &amp;#39;Sales&amp;#39; and &amp;#39;Engineering&amp;#39; to showcase tie-handling\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;Charlie Brown&amp;#39;, &amp;#39;Engineering&amp;#39;, 95000.00),\n(4, &amp;#39;Diana Prince&amp;#39;, &amp;#39;Marketing&amp;#39;, 82000.00),\n(5, &amp;#39;Evan Wright&amp;#39;, &amp;#39;Sales&amp;#39;, 75000.00),\n(6, &amp;#39;Fiona Gallagher&amp;#39;, &amp;#39;Engineering&amp;#39;, 110000.00),\n(7, &amp;#39;George Clark&amp;#39;, &amp;#39;Sales&amp;#39;, 75000.00),\n(8, &amp;#39;Hannah Abbott&amp;#39;, &amp;#39;Marketing&amp;#39;, 68000.00);\n\n-- 3. EXECUTE RANKING QUERY\nSELECT \n    employee_id,\n    employee_name,\n    department,\n    salary,\n    -- Unique row index per record\n    ROW_NUMBER() OVER (ORDER BY salary DESC) AS row_num,\n    \n    -- Traditional rank (Skips ranks after ties: 1, 2, 2, 2, 5...)\n    RANK() OVER (ORDER BY salary DESC) AS standard_rank,\n    \n    -- Dense rank (No gaps in ranking order: 1, 2, 2, 2, 3...)\n    DENSE_RANK() OVER (ORDER BY salary DESC) AS dense_rank\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;) &amp;quot;,0],[&amp;quot;NOT&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;NULL&amp;quot;,3],[&amp;quot;,\n    department VARCHAR(&amp;quot;,0],[&amp;quot;50&amp;quot;,6],[&amp;quot;) &amp;quot;,0],[&amp;quot;NOT&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;NULL&amp;quot;,3],[&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;) &amp;quot;,0],[&amp;quot;NOT&amp;quot;,3],[&amp;quot; &amp;quot;,0],[&amp;quot;NULL&amp;quot;,3],[&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;-- Includes identical salaries in &amp;#39;Sales&amp;#39; and &amp;#39;Engineering&amp;#39; to showcase tie-handling&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;Charlie Brown&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;4&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;5&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;&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;6&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;7&amp;quot;,6],[&amp;quot;, &amp;quot;,0],[&amp;quot;&amp;#39;George Clark&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;8&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 RANKING QUERY&amp;quot;,5],[&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    &amp;quot;,0],[&amp;quot;-- Unique row index per record&amp;quot;,5],[&amp;quot;\n    ROW_NUMBER() &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; row_num,\n    \n    &amp;quot;,0],[&amp;quot;-- Traditional rank (Skips ranks after ties: 1, 2, 2, 2, 5...)&amp;quot;,5],[&amp;quot;\n    RANK() &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; standard_rank,\n    \n    &amp;quot;,0],[&amp;quot;-- Dense rank (No gaps in ranking order: 1, 2, 2, 2, 3...)&amp;quot;,5],[&amp;quot;\n    DENSE_RANK() &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; dense_rank\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;QrODie_10|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;QrODie_10&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=QrODie_11/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;QrODie_11&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;QrODie_12|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;QrODie_12&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;CAAIDxAA&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;2ahUKEwiZ8bbs69qXAxX8yTgGHaCGB-gQ-q4QegYIAAgPEAA&quot; jsaction=&quot;rcuQ6b:&amp;amp;QrODie_13|npT2md;scroll:&amp;amp;QrODie_13|ZUljYd&quot; jscontroller=&quot;kbUand#UYOFMe&quot; jsuid=&quot;QrODie_13&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;2ahUKEwiZ8bbs69qXAxX8yTgGHaCGB-gQw4oVegYIAAgPEAE&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;QrODie_14&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;QrODie_15&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;employee_id&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;QrODie_16&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;QrODie_17&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;QrODie_18&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;QrODie_19&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;row_num&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;QrODie_1a&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;standard_rank&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;QrODie_1b&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;dense_rank&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;2ahUKEwiZ8bbs69qXAxX8yTgGHaCGB-gQw4oVegYIAAgPEAI&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;QrODie_1c&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;QrODie_1d&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;6&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;QrODie_1e&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;QrODie_1f&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;QrODie_1g&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;QrODie_1h&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_1i&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;1&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_1j&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_1k&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;1&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_1l&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_1m&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;1&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&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;2ahUKEwiZ8bbs69qXAxX8yTgGHaCGB-gQw4oVegYIAAgPEAM&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;QrODie_1n&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;QrODie_1o&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;QrODie_1p&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;QrODie_1q&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;QrODie_1r&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;QrODie_1s&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_1t&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;2&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_1u&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_1v&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;2&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_1w&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_1x&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;2&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&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;2ahUKEwiZ8bbs69qXAxX8yTgGHaCGB-gQw4oVegYIAAgPEAQ&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;QrODie_1y&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;QrODie_1z&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_20&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;QrODie_21&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;QrODie_22&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;QrODie_23&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_24&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;3&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_25&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_26&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;2&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_27&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_28&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;2&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&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;2ahUKEwiZ8bbs69qXAxX8yTgGHaCGB-gQw4oVegYIAAgPEAU&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;QrODie_29&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;QrODie_2a&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;4&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;QrODie_2b&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;QrODie_2c&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;QrODie_2d&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;QrODie_2e&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_2f&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;4&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_2g&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_2h&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;4&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_2i&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_2j&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;3&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&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;2ahUKEwiZ8bbs69qXAxX8yTgGHaCGB-gQw4oVegYIAAgPEAY&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;QrODie_2k&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;QrODie_2l&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;2&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;QrODie_2m&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;QrODie_2n&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;QrODie_2o&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;QrODie_2p&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_2q&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;5&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_2r&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_2s&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;5&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_2t&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_2u&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;4&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&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;2ahUKEwiZ8bbs69qXAxX8yTgGHaCGB-gQw4oVegYIAAgPEAc&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;QrODie_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;QrODie_2w&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;5&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;QrODie_2x&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;Evan Wright&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;QrODie_2y&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;QrODie_2z&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;QrODie_30&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_31&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;6&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_32&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_33&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;5&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_34&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_35&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;4&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&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;2ahUKEwiZ8bbs69qXAxX8yTgGHaCGB-gQw4oVegYIAAgPEAg&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;QrODie_36&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;QrODie_37&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;7&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;QrODie_38&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); margin: 0px;&quot;&gt;George Clark&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;QrODie_39&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;QrODie_3a&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;QrODie_3b&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_3c&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;7&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_3d&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_3e&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;5&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_3f&quot; style=&quot;border-bottom: 1px solid rgb(220, 223, 229); 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;QrODie_3g&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;4&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&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;2ahUKEwiZ8bbs69qXAxX8yTgGHaCGB-gQw4oVegYIAAgPEAk&quot; data-visible=&quot;1&quot; jsaction=&quot;&quot; jscontroller=&quot;zVAPJb#QvDBvf&quot; jsuid=&quot;QrODie_3h&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;QrODie_3i&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); margin: 0px;&quot;&gt;8&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;QrODie_3j&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;QrODie_3k&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;QrODie_3l&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;QrODie_3m&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;QrODie_3n&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;8&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_3o&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;QrODie_3p&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;8&lt;!--TgQPHd|||[]--&gt;&lt;/span&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;QrODie_3q&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;QrODie_3r&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;5&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/td&gt;&lt;!--TgQPHd|||[]--&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;!--TgQPHd|||[[1,0,0,7,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;QrODie_3s|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;QrODie_3s&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=QrODie_3t/fLk2Md&quot; jsaction=&quot;&quot; jscontroller=&quot;zg1ZQe#TswZNc&quot; jsuid=&quot;QrODie_3t&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;Key Takeaways from the Data Visual&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;CAAIERAA&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;QrODie_3u&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;CAAIERAB&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;QrODie_3v&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;QrODie_3w&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;QrODie_3x&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;Alice and Charlie&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt; both make &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;QrODie_3y&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;$95,000.00&lt;!--TgQPHd|||[]--&gt;&lt;/code&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;QrODie_3z&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;RANK&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; places them both at &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;QrODie_40&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;2&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;, and skips &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;QrODie_41&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;3&lt;!--TgQPHd|||[]--&gt;&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;QrODie_42&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;DENSE_RANK&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; places them at &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;QrODie_43&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;2&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;, but the next person down (Diana) gets &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;QrODie_44&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;3&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;.&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;CAAIERAC&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;QrODie_45&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;QrODie_46&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;QrODie_47&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;Bob, Evan, and George&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt; all make &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;QrODie_48&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;$75,000.00&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt;. Notice how &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;QrODie_49&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;RANK&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; skips all the way from &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;QrODie_4a&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;5&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt; to &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;QrODie_4b&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;8&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt; for the final row, while &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;QrODie_4c&quot; style=&quot;border-bottom: 1px solid rgb(240, 242, 245); font-size: 14px; margin: 0px;&quot;&gt;DENSE_RANK&lt;!--TgQPHd|||[]--&gt;&lt;/code&gt; moves perfectly from &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;QrODie_4d&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;4&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt; to &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;QrODie_4e&quot; style=&quot;border-bottom: 0px rgb(22, 23, 26); font-weight: 700; margin: 0px;&quot;&gt;5&lt;!--TgQPHd|||[]--&gt;&lt;/span&gt;.&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;QrODie_4f|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;QrODie_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;CAAIEhAA&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;QrODie_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;CAAIEhAB&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;QrODie_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;QrODie_4k|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;QrODie_4k&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;QrODie_4m|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;QrODie_4m&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;QrODie_6z|npT2md&quot; jscontroller=&quot;UTzWVc#U8DOt&quot; jsuid=&quot;QrODie_6z&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;QrODie_70&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;QrODie_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;QrODie_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;QrODie_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;QrODie_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;QrODie_1|ZUljYd;requestToggleBottomSheet:&amp;amp;QrODie_1|aXD3Gb&quot; jsuid=&quot;QrODie_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;QrODie_h,QrODie_i&quot; jsaction=&quot;rcuQ6b:&amp;amp;QrODie_g|npT2md&quot; jscontroller=&quot;CAwPlc#Hx4Oqd&quot; jsuid=&quot;QrODie_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;!--TgQPHdQrODie_1/YOIIaf;QrODie_1/VWapad|||[{&amp;quot;s&amp;quot;:false,&amp;quot;i&amp;quot;:&amp;quot;QrODie_1/YOIIaf&amp;quot;},{&amp;quot;s&amp;quot;:null,&amp;quot;i&amp;quot;:&amp;quot;QrODie_1/VWapad&amp;quot;},156,{&amp;quot;s&amp;quot;:null,&amp;quot;i&amp;quot;:&amp;quot;QrODie_1/C5DOxd&amp;quot;},[&amp;quot;AimExportActionToastLink&amp;quot;,309275],&amp;quot;\u0026QrODie_1:bREfu&amp;quot;,false]--&gt;&lt;/div&gt;&lt;!--TgQPHd|QrODie_1/YOIIaf;QrODie_1/LL5gb;QrODie_1/We76zc;QrODie_1/VWapad;QrODie_1/C5DOxd||[[null,0,null,0,null,0,[&amp;quot;Write a query to rank employees based on salary? write table schema and insert data also&amp;quot;],null,0,[&amp;quot;Write a query to rank employees based on salary? write table schema and insert data also&amp;quot;],0]]--&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/5634986291259401733/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/write-query-to-rank-employees-based-on.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/5634986291259401733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/5634986291259401733'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/write-query-to-rank-employees-based-on.html' title='Write a query to rank employees based on 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-4742099952934311984</id><published>2026-10-26T22:30:00.000-07:00</published><updated>2026-10-27T07:12:12.015-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'>Running total of salaries by department.</title><content type='html'>&lt;h1&gt;Running Total of Salaries by Department in SQL: A Complete Guide&lt;/h1&gt;
&lt;p&gt;&lt;em&gt;How to build cumulative totals with window functions, avoid the common pitfalls, and keep the query fast&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;A cumulative number shows up in almost every reporting request: sales to date, headcount growth, or, in this guide, &lt;strong&gt;the running total of salaries within each department&lt;/strong&gt;. A running total shows how a value accumulates row by row, and it resets whenever the group changes.&lt;/p&gt;
&lt;p&gt;Before window functions, this meant a self-join or a correlated subquery, both slow and hard to read. Today a single &lt;code&gt;SUM() OVER (...)&lt;/code&gt; does the job. This post walks through the full solution, explains each clause, covers the mistakes that trip people up, and finishes with performance tuning.&lt;/p&gt;
&lt;h2&gt;The Scenario&lt;/h2&gt;
&lt;p&gt;We have an &lt;code&gt;Employees&lt;/code&gt; table and want to see, for every employee, how much the department&#39;s payroll has accumulated as of their hire date.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE Employees (
    EmployeeId INT PRIMARY KEY,
    Name       VARCHAR(100),
    Department VARCHAR(50),
    Salary     DECIMAL(10,2),
    HireDate   DATE
);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Sample data:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;INSERT INTO Employees (EmployeeId, Name, Department, Salary, HireDate) VALUES
(1, &#39;Asha&#39;,  &#39;Engineering&#39;, 90000, &#39;2020-01-10&#39;),
(2, &#39;Ravi&#39;,  &#39;Engineering&#39;, 85000, &#39;2021-03-05&#39;),
(3, &#39;Meera&#39;, &#39;Engineering&#39;, 95000, &#39;2022-07-19&#39;),
(4, &#39;Karan&#39;, &#39;Sales&#39;,       60000, &#39;2019-11-02&#39;),
(5, &#39;Neha&#39;,  &#39;Sales&#39;,       65000, &#39;2021-06-14&#39;);
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;The Solution&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT
    Department,
    EmployeeId,
    Name,
    HireDate,
    Salary,
    SUM(Salary) OVER (
        PARTITION BY Department
        ORDER BY HireDate, EmployeeId
        ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
    ) AS RunningTotal
FROM Employees
ORDER BY Department, HireDate, EmployeeId;
&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;Department&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;HireDate&lt;/th&gt;
&lt;th align=&quot;right&quot;&gt;Salary&lt;/th&gt;
&lt;th align=&quot;right&quot;&gt;RunningTotal&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;Asha&lt;/td&gt;
&lt;td&gt;2020-01-10&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;90,000&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;90,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Engineering&lt;/td&gt;
&lt;td&gt;Ravi&lt;/td&gt;
&lt;td&gt;2021-03-05&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;85,000&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;175,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Engineering&lt;/td&gt;
&lt;td&gt;Meera&lt;/td&gt;
&lt;td&gt;2022-07-19&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;95,000&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;270,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sales&lt;/td&gt;
&lt;td&gt;Karan&lt;/td&gt;
&lt;td&gt;2019-11-02&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;60,000&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;60,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sales&lt;/td&gt;
&lt;td&gt;Neha&lt;/td&gt;
&lt;td&gt;2021-06-14&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;65,000&lt;/td&gt;
&lt;td align=&quot;right&quot;&gt;125,000&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Notice that Sales starts again at 60,000 rather than continuing from Engineering&#39;s total. That reset is the point of partitioning.&lt;/p&gt;
&lt;h2&gt;How the Query Works&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;OVER&lt;/code&gt; clause has three parts, and each one controls a different aspect of the calculation.&lt;/p&gt;
&lt;h3&gt;1. PARTITION BY Department&lt;/h3&gt;
&lt;p&gt;This splits the rows into independent groups, one per department. The sum is calculated inside each group, so totals never leak from one department into another. Unlike &lt;code&gt;GROUP BY&lt;/code&gt;, partitioning does &lt;strong&gt;not&lt;/strong&gt; collapse rows. Every employee row stays in the output.&lt;/p&gt;
&lt;h3&gt;2. ORDER BY HireDate, EmployeeId&lt;/h3&gt;
&lt;p&gt;A running total only means something with an order. Here we accumulate in hire-date order. &lt;code&gt;EmployeeId&lt;/code&gt; is added as a &lt;strong&gt;tie-breaker&lt;/strong&gt;: if two employees share a hire date, the database would otherwise be free to order them arbitrarily, and the running totals could change between executions.&lt;/p&gt;
&lt;h3&gt;3. ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW&lt;/h3&gt;
&lt;p&gt;This is the &lt;strong&gt;frame&lt;/strong&gt;. It tells the database which rows, relative to the current one, feed the sum. Here it means &quot;from the first row of the partition through the current row.&quot; That is exactly the definition of a running total.&lt;/p&gt;
&lt;h2&gt;The Common Gotcha: Always Specify ROWS&lt;/h2&gt;
&lt;p&gt;You can write the query without the frame:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SUM(Salary) OVER (PARTITION BY Department ORDER BY HireDate)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It looks equivalent, but it isn&#39;t. Without a frame clause, SQL uses &lt;code&gt;RANGE UNBOUNDED PRECEDING&lt;/code&gt; by default. &lt;code&gt;RANGE&lt;/code&gt; treats rows with equal &lt;code&gt;ORDER BY&lt;/code&gt; values as peers, so if two employees were hired on the same day, &lt;strong&gt;both rows receive the same total&lt;/strong&gt;, which is usually not the intent. In SQL Server, &lt;code&gt;RANGE&lt;/code&gt; is also typically slower because it can spill to disk.&lt;/p&gt;
&lt;p&gt;Writing &lt;code&gt;ROWS&lt;/code&gt; explicitly fixes both problems and makes your intent obvious to the next reader.&lt;/p&gt;
&lt;h2&gt;Variation 1: Monthly Department Payroll&lt;/h2&gt;
&lt;p&gt;Often you want the cumulative payroll over time rather than per employee. Aggregate first with &lt;code&gt;GROUP BY&lt;/code&gt;, then apply the window function on top of the result:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;WITH Monthly AS (
    SELECT Department,
           DATEFROMPARTS(YEAR(HireDate), MONTH(HireDate), 1) AS Month,
           SUM(Salary) AS MonthlySalary
    FROM Employees
    GROUP BY Department, DATEFROMPARTS(YEAR(HireDate), MONTH(HireDate), 1)
)
SELECT Department, Month, MonthlySalary,
       SUM(MonthlySalary) OVER (
           PARTITION BY Department
           ORDER BY Month
           ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
       ) AS RunningTotal
FROM Monthly
ORDER BY Department, Month;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The CTE (&lt;code&gt;WITH Monthly AS ...&lt;/code&gt;) produces one row per department per month. The outer query then accumulates those monthly figures. This two-step pattern, aggregate then window, is useful any time you need a running total over time periods.&lt;/p&gt;
&lt;h2&gt;Variation 2: Running Total Beside the Department Total&lt;/h2&gt;
&lt;p&gt;You can use several windows in the same query. This version shows the running total and the department&#39;s overall total on every row:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT Department, Name, Salary,
       SUM(Salary) OVER (
           PARTITION BY Department
           ORDER BY Salary DESC, EmployeeId
           ROWS UNBOUNDED PRECEDING
       ) AS RunningTotal,
       SUM(Salary) OVER (PARTITION BY Department) AS DepartmentTotal
FROM Employees;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The second &lt;code&gt;SUM&lt;/code&gt; has no &lt;code&gt;ORDER BY&lt;/code&gt;, so it covers the whole partition and returns the same total on every row of the department. From here, the share of the department payroll reached so far is simply:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;RunningTotal * 100.0 / DepartmentTotal
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ordering by &lt;code&gt;Salary DESC&lt;/code&gt; makes this a &quot;top earners first&quot; view, which is handy for seeing how much of the payroll the highest-paid people account for.&lt;/p&gt;
&lt;h2&gt;Variation 3: Without Window Functions&lt;/h2&gt;
&lt;p&gt;On very old databases that lack window functions, a correlated subquery gives the same result:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;SELECT e.Department, e.Name, e.Salary,
       (SELECT SUM(e2.Salary)
        FROM Employees e2
        WHERE e2.Department = e.Department
          AND (e2.HireDate &amp;lt; e.HireDate
               OR (e2.HireDate = e.HireDate AND e2.EmployeeId &amp;lt;= e.EmployeeId))
       ) AS RunningTotal
FROM Employees e;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It works, but it re-scans the table for every output row, so cost grows quickly with data size. The window version reads the data once, which is why it is the preferred approach wherever it&#39;s available.&lt;/p&gt;
&lt;h2&gt;Performance Tuning&lt;/h2&gt;
&lt;p&gt;An index that matches the &lt;code&gt;PARTITION BY&lt;/code&gt; and &lt;code&gt;ORDER BY&lt;/code&gt; columns lets the database read rows already in the right order and skip a separate sort:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE INDEX IX_Employees_Dept_Hire
ON Employees (Department, HireDate, EmployeeId)
INCLUDE (Salary);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The key columns follow the partition and sort order, and &lt;code&gt;INCLUDE (Salary)&lt;/code&gt; makes the index covering, so the query never has to visit the base table.&lt;/p&gt;
&lt;p&gt;Other tips:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Filter early.&lt;/strong&gt; Apply &lt;code&gt;WHERE&lt;/code&gt; conditions before the window is computed so fewer rows are processed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Read the execution plan.&lt;/strong&gt; A Sort or Spool operator usually means the index doesn&#39;t match the window&#39;s partition and order columns.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Select only what you need.&lt;/strong&gt; Wide result sets make the window operator more expensive.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Database Compatibility&lt;/h2&gt;
&lt;p&gt;This syntax works in:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Database&lt;/th&gt;
&lt;th&gt;Support&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Azure SQL Database / SQL Server&lt;/td&gt;
&lt;td&gt;2012 and later&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PostgreSQL&lt;/td&gt;
&lt;td&gt;8.4 and later&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MySQL&lt;/td&gt;
&lt;td&gt;8.0 and later&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Oracle&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SQLite&lt;/td&gt;
&lt;td&gt;3.25 and later&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The only dialect-specific part of the examples is &lt;code&gt;DATEFROMPARTS&lt;/code&gt;. In PostgreSQL, replace it with &lt;code&gt;DATE_TRUNC(&#39;month&#39;, HireDate)&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Key Takeaways&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Use &lt;code&gt;SUM() OVER (PARTITION BY ... ORDER BY ...)&lt;/code&gt; for running totals instead of self-joins or subqueries.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;PARTITION BY&lt;/code&gt; resets the total per group, and unlike &lt;code&gt;GROUP BY&lt;/code&gt; it keeps every row.&lt;/li&gt;
&lt;li&gt;Add a unique tie-breaker column to the &lt;code&gt;ORDER BY&lt;/code&gt; for deterministic results.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Always specify &lt;code&gt;ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW&lt;/code&gt;&lt;/strong&gt; to avoid tie-related surprises and the slower &lt;code&gt;RANGE&lt;/code&gt; default.&lt;/li&gt;
&lt;li&gt;To get cumulative values over time, aggregate first in a CTE, then apply the window.&lt;/li&gt;
&lt;li&gt;Back the query with an index on the partition and order columns, including the summed column.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;&lt;br /&gt;&lt;/h2&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspmaterials.blogspot.com/feeds/4742099952934311984/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/running-total-of-salaries-by-department.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/4742099952934311984'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5356089030550857026/posts/default/4742099952934311984'/><link rel='alternate' type='text/html' href='http://aspmaterials.blogspot.com/2026/10/running-total-of-salaries-by-department.html' title='Running total of salaries by 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>