add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE S(
ID VARCHAR(50),
Type VARCHAR(4),
Quality VARCHAR(4),
FldOrLab VARCHAR(5),
PID VARCHAR(50),
sample_date VARCHAR(10),
sample_time VARCHAR(8)
)

INSERT INTO S
VALUES ('12345MSD','SD','WQ','Lab','12345','03/28/2023','08:16'),
('12345MSD','SD','WQ','Lab','12345','03/28/2023','09:38'),
('12345MSD','SD','WQ','Lab','12345','03/29/2023','07:46'),
('12345MSD','SD','WQ','Lab','12345','03/29/2023','08:26'),
('12345MSD','SD','WQ','Lab','12345','03/30/2023','08:24')



select a.ID, a.Type, a.Quality, a.FldOrLab,a.PID,a.sample_date,a.sample_time, (SELECT COUNT(*) FROM S WHERE ID=a.ID and sample_date<=a.sample_date and sample_time<=a.sample_time) as RowOrder
from s as a
ID Type Quality FldOrLab PID sample_date sample_time RowOrder
12345MSD SD WQ Lab 12345 03/28/2023 08:16 1
12345MSD SD WQ Lab 12345 03/28/2023 09:38 2
12345MSD SD WQ Lab 12345 03/29/2023 07:46 1
12345MSD SD WQ Lab 12345 03/29/2023 08:26 3
12345MSD SD WQ Lab 12345 03/30/2023 08:24 3
select a.ID, a.Type, a.Quality, a.FldOrLab,a.PID,a.sample_date,a.sample_time, (SELECT COUNT(*) FROM S WHERE ID=a.ID and sample_date + ' ' + sample_time <= a.sample_date + ' ' + a.sample_time) as RowOrder
from s as a
ID Type Quality FldOrLab PID sample_date sample_time RowOrder
12345MSD SD WQ Lab 12345 03/28/2023 08:16 1
12345MSD SD WQ Lab 12345 03/28/2023 09:38 2
12345MSD SD WQ Lab 12345 03/29/2023 07:46 3
12345MSD SD WQ Lab 12345 03/29/2023 08:26 4
12345MSD SD WQ Lab 12345 03/30/2023 08:24 5