I have one t_table(some_date, id), and i want get count of ids for each day between two input dates. I try this query: SELECT dateDiff(‘day’, toDateTime(‘2020-07-01 07:34:22’), some_date) as day, …
How to SELECT two records for each unique column value as one row in MySQL?
I have a MySQL table like this : +—-+—–+——-+——+——+——-+———————+ | ID | GID | Name | p1 | p10 | p100 | createdAt | +—-+—–+——-+——+——+—-…
Yes/No Format for query column
I have the following query, simplified for this question: SELECT convert(bit, Substring(Max(convert(CHAR(8), tt.transaction_dt, 112) + convert(CHAR(1), tt.trans_live)), 9, 1)) AS is_live FROM …
SQL customer who never order product p1 and p2 together
I do have two table. I want to find customers who never order product p1 and p2 together(there are million rows in this table) Answer If I understand you correctly, with your very limited information, here is the solution. I broke it up to pieces, for you to understand it better
Implementing Two Level Aggregate in PostgreSQL using Sequelize Function for NodeJS App
Hello guys please bear with me here. I’m using PostgreSQL, Sequelize, Express, and NodeJS to create a backend. I’m wondering if these lines of raw query code can be implemented using Sequelize Model …
Is it possible to commit a transaction and start a new one without releasing the row locks?
I have a use case where I need to: Update a row. Persist the changes to disk, such that a system crash will not reverse it. Update the same row that has not been modified by another transaction (a …
How to rank values in SQL for an existing and pre-arranged set
I will need the implementation in SQL only and not PL-SQL or any other programming method. Answer This is a gaps-and-islands problem. In this case, lag() and a cumulative sum does what you want:
Using top N in sql
statement 1 statement 2 I have tried the above but both are not working. Does anybody know the reason? Answer If you want to update one row, then you can use limit: That said, I would expect id to be unique, so no LIMIT is necessary.
SQL transforming one row to columns with unknown number of distinct values
I have a following database And the result I want to achieve would look like so, with values for system_code columns being sum of “value” My problem is that there is over 1000 distinct values for system_code so I can’t type them by hand. Database has nearly billion entries so anything that w…
Recursive query in Oracle until a parent in the hierarchy meets a condition?
I have a table like the following: And I’d like to be able to fetch each ID with its corresponding VALUE_ID. I want to do it in such a way that if a row has a VALUE_ID as NULL, it “inherits” the VALUE_ID of the first parent above it in the hierarchy, that has a VALUE_ID as NOT NULL. So