Skip to content
Advertisement

Tag: subquery

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

Advertisement