For the given table below, how can we find the customer whose name appears 3 times consecutively. Desired_Output Table Definition: Code Tried so far I believe we can do this by using lead/lag to get the previous and next row. Although my solution gives the desired output but i don’t think this is correct solution. Answer Your method is close.
Tag: sql
Something wrong with this SQL query?
Is there something wrong with this query? SELECT id, ( 6371 * acos(cos(radians(?1)) * cos(radians(latitud)) * cos(radians(longitud) – radians(?2)) + sin(radians(?1)) * sin(radians(latitud)))) …
Limiting SQL query to 10,000 results by where clause only, by string field
I have an interesting issue that I’m struggling to solve. I am retrieving data from a DB via a web API. I have direct DB access for testing, but my application will need to read the data via the API. In the API I can essentially provide the where clause for the SQL statement that retrieves my data from the
how do we check if an element in the array exists and if it has a value of “true” in Presto
The data in the array looks like XXXX:”False”. I used element_at(array_name,’Field’) and contains(map_keys(array_name),’Field’). They only check if the element is present in the array. But if the ‘Field’ has a value of ‘true’, How do i check that value? Answer Assuming that you have a map at hand, and that you want to check the value of of a given
SQL Column Contains ID of Another Row
Suppose I have a SQL database my_table of the following form where one column contains the id of another row. How can I select both the name column of the given row and the name of the underlying id …
Join and flatten table output
I am currently trying to join 3 tables. The main table is company, if there is 3 companies and 2 roles exists in the role table I want the output to be like this: Company1, Role 1, …
How to distribute values when prior rank is zero
Not certain how to title this question. Describing is a bit of a challenge, too. I have shaped my postgres data as follows, where a location and geo is further broken out into micro geo’s based on …
SQLite: How to retrieve data from column in one table using SELECT to insert retrieved data in another table
I am attempting to use SQLite to retrieve data from the main table (mutants.info) and insert data from that table into a secondary table (mutants.teams). The main table has multiple columns, but I am …
User with multiple companies (different type)
I built an application in Laravel that is a simple CRUD app. Now im struggling with migrations a bit. User belongs to Company. Company can have many users. Company type can be Supplier, Customer or …
Retrieve all records with the 5 most recent distinct dates
I need to retrieve data for a history module with pagination. The requirement is to show the records for the five most recent dates first (regardless of the number of rows) and load the remaining records in lots (next five dates, any number of rows) as requested by the user. I came up with the query below, which is extremely