I have a historical table with data like as bellow : The EXP_DT is null mean that the row is active. I want to return a group of data each time Status changes The expected result like as bellow : Thanks for help ! Answer This is classic gaps-and-islands problem. We can solve it by using LAG to check for
Tag: sql
Prevent Duplicate Entries in SQL Application
I have an application that’s running on two different machines. The use of the application is pretty simple, we scan a product and it associates the product_id and creates a Unique_ID that’s auto-incremental. Ex: U00001 then the next is U00002 My problem is while both the machines are running, som…
use sql case statement in a adoquery of delphi
so i want to calculate a sum of a field using adoquery and case statement in delphi ; the code i use is this : but i gest an error message : syntax error operator absent in the expression case when month(DATE_PAI)=1 then sum(MT) else 0 end can any one help me please Answer Try to do : (group SELECT
SQL Select Distinct Top5 with Order By and Where
I have a table where Employees can check assets and each of their checks is recorded in a table. Now I want to extract the 5 last checked Asset_Ids for a given employee. He might have checked the same asset more than once, each check is recorded in a table -EmployeeLog- Basically my table has 3 columns : Empl…
Problem with PostgreSQL function parameter of type “name”
I’m writing some PostgreSQL functions to compile a list of search terms for records in a table called name. Since the search terms come from multiple columns on the name table and from multiple columns on other tables, a simple generated column isn’t sufficient. Here’s a simplified version o…
How to convert SQL query in laravel query?
I know this question is not asked in a well manner way,so I am sorry,I have SQL query this one I want to convert it in PHP laravel query form so tried this query but I don’t know SQL and even I am not understanding how I convert it, can someone help just convert SQL query to laravel query? here
how to filter data in sql
I am trying to filter the data according to several criteria, and based on these criteria, the record record number 7 (M08) should not appear because the “NewSiteID” column is not null and does not belong to the number 6, but the problem is that this record appears even though I used the condition…
Selecting last record in plsql
Hello I need to select last record in a table(bill_account_billcycle). After finding it I need to take bill_date column date from last record and need implement inside my cursors’ query. I read rownum max etc but couldnt succeed to implement. I am open to advices. I am going to add a screenshoot of one …
Why can’t I sum values for a given period with intervals present in another table?
I’m using a software. I can not change the model. The software is a film rental manager. In the database, I have some clients and differents type of rental and different type of client (free, vip, vip+, …) A client can rent a movie for one day, one week, buy a movie, etc. He starts as a free clien…
Split large texts into chunks in separate rows
I have a table, where some texts are atrociously big. I want to make sure every row in the query output does not exceed, say, 100.000 characters. How do I do that? Here is a quick sample: Let’s say I want output text column to be less than 10 characters. So, I need this result: It would be even better