I have been working on this for a few weeks and I know there’s a way like using ROW_NUMBER(), but I’m just not too familiar with it, Or maybe there’s a better way…. shows this: It needs to show this: As you can see, there’s 2 delete dates for SKU 555454, and it has to show the la…
Tag: sql
Sum of two counts from one table with additional data from another table
I have two tables as follows: I want to get the sum of two counts, which are the number of true values in col_a and number of true values in col_b. I want to group that data by user_id. I also want to join Table B and get the name of each user. The result would look like this: So
SQLite update data from one table to another
I’m trying to insert some data from one SQLite database to another. I have 2 tables called “members” and “attendance.” What’s supposed to happen is, everytime a new member is added into the member table (or removed), the name and ID of the specific member should also be add…
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). Th…
Aggregate function MAX giving unexpected output when used inside a HAVING clause
The Table Id Salary 1 100 2 200 3 300 I want to find out all the salaries lesser the highest salary. For doing so, i have come up with the following query- Which yields the output- {“headers”: [“salary”], “values”: [[100]]} But my expected output here is {“headersR…
How to iterate rows with known start position and mixed column ordering, exactly as if walking the corresponding index?
I have a given, unmodifiable table design which resembles: I simply want to iterate rows from this table in the order c1 asc, c2 desc, starting at a known position, e.g., (‘foo’, 5). The query must be efficient, i.e. the query planner must be able to take advantage of the unique index and do an in…
SQL Server 2014 slow remote insert
I have several linked servers and I want insert a value into each of those linked servers. On first try executing, I’ve waited too long for the INSERT using CURSOR. It’s done for about 17 hours. But I’m curious for those INSERT queries, and I checked a single line of my INSERT query using Di…
Break ranges into rows Teradata
I have an input like this: I would link to break each range into rows: I’m trying to get this output in TERADATA, can you guys help me? Thanks a lot. Answer Teradata’s proprietary EXPAND ON syntax is for creating time series, but can used for your task, too. Assuming TD16.20+ this can be further s…
Convert SQL to Laravel ORM RELATONS
It is working but I should do with Relaion Like this… But it is not working because whereHas returns a collection, What I can do ??? Please give advice. Answer This is working thank you !!!
Azure Data Bricks – Convert to Date for Ordering
I have had to construct a string that has a millisecond compoment as source where data is being extracted does not allow a date field to hold a milli second component. However not the problem .. Query The problem is that I can not order records in Azure Data Bricks Sql Analaytics using the STRING version of t…