Skip to content

Output of non-existent values when grouping in sql

For example, i have a table with the data: Screenshot This table named “table”. I have the SQL query: And I get the result: Question: how do I write a query that would return all the values that are in the kind field (or any other field that can be in group by)? Even if this value is 0. For

Why are these 2 queries giving different outputs?

Query no 1:- The Query 1 gives me the following output:- Query no 2:- The Query 2 gives me the following output:- Answer Summary: The AND operator has higher precedence than the OR operator. To fix it, use brackets around the OR expression. AND has higher precedence than OR so your first query is the equivalent of (with added brackets

Exclude Records Based on Criteria

I need to exclude the record: If a customer bought “Shoe” and “Hat” on the same day, exclude the record with “Hat”. If a customer bought “Shoe” and “Cloth” on the same day, exclude the record with “Cloth”. Here is the sample data: Here are the expected results: Answer Self join to your shoe criteria and make sure it is


I have created a WITH RECURSIVE function and would like to use it with an INSERT INTO function so that the results insert into the path column. category_id category_name parent_id path 1 Root 0 2 Fishing 1 3 Sea 2 4 Lures 3 7 Coarse 2 8 Lures 7 9 Fly 2 I have tried the following code but the

How to apply this query to all the employees

I have a query to compute the 3rd highest salary for an employee as shown below. How can I apply this query to give the 3rd highest salary for each employee which can be fetched by the query Note: without using special functions like dense_rank() Answer You are looking for each employee’s third highest salary. It can happen that we

SQL Select Duplicate Values based on Specific Condition

I am asking for a solution where I can find duplicate entries in a table but one of those duplicate entries MUST contain a specific value otherwise it won’t come in the result. For example, my table is like this: ID Name Type 1 Hassan Commercial 2 Ahmed Personal 3 Jack Personal 4 Hassan Commercial 5 Jack Commercial 6 Charlie

What am I getting wrong in this SQL query?

Write a query that retrieves only a ranked list of the most prolific days in October 2020, prolific measured in number of posts per day. Your query should return those days in a single-column table (column name post_day) in the format YYYY-MM-DD. This is my table: This is my query: The problem is that I’m only getting one result, not

SQL case expression divide values for percentage

I’m trying to divide two values to get the percentage. I need the ‘VA’ AUM / ‘TOTAL’ AUM to get the percentage. Below are the two different methods that I have tried, but they are not providing the percentage. The first method only provides ‘NULL’. How do I take the product of ‘VA’ and the AUM field value and divide