Update Duplicate Data [closed] - sql

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 9 years ago.
Improve this question
I have a Calisma Database and it has DosyaNo and SiraNo columns.
I want to set SiraNo where DosyaNo is same for example
DosyaNo ____________SiraNo
0.00000000__________1
0.00000000__________2
0.00000000__________3
0.00000000__________4
0.00000000__________5
---------------------
0.10000000__________1
0.10000000__________2
0.10000000__________3
0.10000000__________4
0.10000000__________5
-----------------------
0.70000000__________1
0.70000000__________2
0.70000000__________3
------------------------
7.10000000__________1
7.10000000__________2

You can use CTE for that
WITH cte AS
(
SELECT DosyaNo, SiraNo,
ROW_NUMBER() OVER (PARTITION BY DosyaNo ORDER BY (SELECT NULL)) rnum
FROM table1
)
UPDATE cte
SET SiraNo = rnum
Here is SQLFiddle demo

Related

Tracking Employee Changes - SQL query [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 11 hours ago.
Improve this question
I have this table of employees that gets updated at the end of each month. I know how to detect changes (2 rows; one of old and one of new) but I need to summarize the changes as showing in the second table using sql query.
With JobHistory AS(
Select
*,
LEAD([DepartmentName]) over (Partition by [EmployeeNumber] order by [ASofDate]) as NewDepartmentName,
LAG([DepartmentName]) over (Partition by [EmployeeNumber] order by [ASofDate]) as OldDepartmentName
FROM [EmployeeDirectory]
)
Select *
FROM JobHistory
WHERE (
(NewDepartmentName <> [DepartmentName])
OR
( OldDepartmentName <> [DepartmentName])
)
ORDER by AsOfDate, EmployeeNumber
[Table]
Required Results

Get CR_NO values for the same table in sql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Some can help me on this query? I need this
You can use the exists as follows:
Select cr_no, so, id
From your_table t
Where exists (select 1 from your_table tt
Where t.cr_no <> tt.cr_no
And t.so = tt.so
And t.id = tt.id)

How can we display the last 7 Records from table in Oracle 11G SQL only? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
How can I write this query without TOP and Limit only use the SQL
You just sort the data one way, grab the records you want, then sort it the other way:
SELECT SOME_FIELD
FROM (SELECT st.*
FROM SOME_TABLE st
ORDER BY SOME_FIELD DESC)
WHERE ROWNUM <= 7
ORDER BY SOME_FIELD ASC
dbfiddle here

To select max date and time [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 3 years ago.
Improve this question
I have data with column createdate like '24/04/2019 14:52:38',24/04/2019 14:52:37,24/04/2019 14:52:35,24/03/2019 14:52:38 etc.
how to get data based on max date and time in SQL query.
select
top(1) *
from
xx
order by
createdate desc
something like this? (works if createdate column is of date/datetime/timestamp type)
select
*
from
<table_name>
where
createdate = (select
max(createdate)
from
<table_name>)

SQL query on table [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 8 years ago.
Improve this question
I have a table like the following
sl.no Machine Id date status
I need to get the last status for each machine ID for each day.(Everyday each machine ID will have many entries .I need to get the last entry for that day for each machine ID)
Please help
Hope this will solve your issue
Select MachineID, Date,
(Select Top 1 t1.Status
FROM table As t1
WHERE t1.MachineID = table.MachineID
AND t1.Date = table.Date
order by slno desc)
FROM table
Group BY MachineID, Date