I’m trying to get the max and min date values in column C based on the (column A, column B) unique pair combinations. Suppose I have a table like: The output I want to get is: My attempt query has been taking 20 mins to run with no output yet (just tried to get max date from column C for
Tag: subquery
SQL – how to remove whole row if one of the column in subquery return NULL
I am stuck in 1 SQL query This query return 4 row ( As shown in the screenshot ) I want a scenario like : If subquery return NULL , then the whole row will not be shown. So in this example “childthree” should not be shown , as “parent_user_email” is NULL , so the whole 3rd row need to
Getting unique record based on max conditions including null values
I need to get back one record of a player’s (Rank A players only) most recent win date (some win dates are null but we need to include them) but picking only the last place of their most recent game session. So basically in that order: get their max win_date (if null, still include them) > from there grab their
Postgres: Count multiple events for distinct dates
People of Stack Overflow! Thanks for taking the time to read this question. What I am trying to accomplish is to pivot some data all from just one table. The original table has multiple datetime entries of specific events (e.g. when the customer was added add_time and when the customer was lost lost_time). This is one part of two rows
How to avoid rerunning a subquery used multiple times?
The following is a simplified example of a problem I’m running into. Assume I have a query “SomeQuery” (SELECT… FROM… WHERE…) that gives an output that looks like this: Status MyDate A 6/14/2021 A 6/12/2021 B 6/10/2021 A 6/8/2021 B 6/6/2021 A 6/4/2021 I need to get the earliest status A date that is greater than the maximum status B
SQL subquery in SELECT clause
I’m trying to find admin activity within the last 30 days. The accounts table stores the user data (username, password, etc.) At the end of each day, if a user had logged in, it will create a new entry in the player_history table with their updated data. This is so we can track progress over time. accounts table: id username
‘WITH’ clause does not work with in operator
I have a simple query: It should create a MaxSal temporary table and then in the WHERE section it should check whether the Salary, DepId are inside said table. Unfortunately, this query gives me ORA-00920: invalid relational operator which I guess is referring to the in operator. If I put the Sub-query directly instead of first putting it in a
How to select a foreign key after narrowing down via Group By and Having in a subquery
I’ve got a unique problem. I’m querying a replicated database table cost_plan_breakdown, and the replication is known to have some duplicates due to issues with deleting records. I’m not the Admin so I’m trying to sidestep these duplicates as efficiently as possible. The table looks like this: sys_id sys_created_on cost_plan breakdown_start_date axr123 2020-10-01 09:31:15 Outlook KTLO – Lisa Lymon 10-01-2020
How can i make this Complex query for SQL database
I have a database that looks like this: Player (UserId, Mail, Password, Username, LastLogin) Leaderboard (UserId*, Level, Kills, Deaths) Match (MatchId, HostId*, ServerIp, StartTime, Team1Points, Team2Points) MatchStats (UserId*, MatchId*, Kills, Deaths) Weapons (IdWeapon, Name, Damage, FireRate, ReloadTime, Range) Inventory(UserId*, WeaponType*, Skin) I need a query that selects the LastLogin of every Player that is dead more than 12 times (MatchStats.Deaths
Using subquery with update SQL
I have Table 1 : EMP as below Table 2: EMP1 ID is the Key and is common in both the files. I want an Update SQL to update the amount field of Table 1 using Amount field of table 2, which gives the result as below. Result: Answer One method is a correlated subquery: You can check if the