I need to find customers that have a sum of credit transactions greater than or equal to a threshold amount and a sum of debit transactions less than or equal to the inverse of that same threshold amount. I also want to return the transactions whose aggregate transaction amount satisfies the credit and debit thresholds. I have come up with
Tag: sql
Date distinct count over week
Im trying to get a distinct count of user ids logs per day with every week as a partition for the distinct identification. e.g. if one user logs on Friday/Saturday of week 1, and on Monday/Friday of …
How to assign a field name to an SQL Count in AWS Athena SQL
I’m still new to Athena. I think I got my database defined correctly, as shown in Example 1 below. However, when I run a count query, I get results unlike what I would expect. Example 1: Works Fine except count is called “_col3” Result: Example 2: syntax error This query shows a syntax error when I click “Run Query”: Answer
Define Position based on lowest ID and Foreign Key in MySQL
I am currently facing the following issue: I have 1 Table with my Broker Trading Data similar to this: The Goal is to say IF first OrderType (lowest Id where TradeId is the same) was a Buy, it’s a LONG Trade ELSE a Short Trade … output should be like this: What am I missing? How can I construct my
How to build a query so that I can find all events along with an extra bool column “attending” which is a join on attendees table?
I have a events table, and I have a events_attendees table which has the event_id and user_id. For example, I want to find events around some user (user_id = 1) but also know whether or not they are attending through that additional column. Here’s the query that would get me the pins where the user is attending, but again I
How to get common value based on a column from a table sql
I have a table. the screenshot is given bellow: There have two columns item_details_id pay_method_id In item_details_id there have 1,2,1 data. On the other hand pay_method_id have 1,1,3 data. I want to get only common values of pay_method_id depending on item_details_id. According to the given screenshot- in item_details_id I have ‘1’ & ‘2’ value. —– ‘1’ pay_method_id is ‘1’, ‘3’
Did this SQL update statement delete records? [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question I ran an update statement like this, last night. where it is joining local data Table_V2 with data on another
What is the correct way to use LEFT JOINS, GROUP BY, and ORDER BY together?
I have an SQL Query (MySQL) which uses a combination of LEFT JOIN, GROUP BUY, ORDER BY, and LIMIT. When I remove LEFT JOIN and GROUP BY it works fine. What is the correct way to add in my additional LEFT JOIN and GROUP logic to make this work? Answer Your syntax is incorrect – where clause will be before
Update table inside a loop in a procedure pl/sql
So i want to hire a new manager for a department. This procedure has 2 parameters, the department name i want to change, and the new id for manager (taken from employee’s id). So to change it, i need …
How to add date rows for messages query?
I got a Messages table. id | sender_id | message | date 1 | 1 | Cya | 10/10/2020 2 | 2 | Bye | 10/10/2020 3 | 1 | Heya | 10/11/2020 I want to insert date rows …