คำถามคือ ผมจะเลือกเฉพาะข้อมูลชุดแรกขึ้นมาโชว์อย่างเดียวต้อง WHERE ยังไงครับ
คำสั่งคิวรี่ของผมครับ
Code
SELECT TOP 300 [tb_reportslist].nUserID , [tb_reportslist].nDeviceID , (CONVERT(NVARCHAR(24),[tb_reportslist].dtDateTime,120))as dtDateTime , [imp_emp].strUserName , [imp_emp].[nUserID], [Device_sukishi].[DeviceID] , [Device_sukishi].[DeviceName] FROM [hr_scan].[dbo].[tb_reportslist] INNER JOIN [hr_scan].[dbo].[imp_emp] ON tb_reportslist.nUserID = imp_emp.[nUserID] INNER JOIN [hr_scan].[dbo].[Device_sukishi] ON tb_reportslist.nDeviceID = Device_sukishi.[DeviceID]
WHERE (CONVERT(date, tb_reportslist.dtDateTime)) BETWEEN '02-02-2015' AND '02-03-2015' AND tb_reportslist.nUserID = '571893' AND (nEvent NOT IN ('23')) order by dtDateTime
ขอบคุณครับ
Tag : PHP, Ms SQL Server 2005, Ms SQL Server 2008, Ms SQL Server 2012
SELECT TOP 1 [tb_reportslist].nUserID , [tb_reportslist].nDeviceID , (CONVERT(NVARCHAR(24),[tb_reportslist].dtDateTime,120))as dtDateTime , [imp_emp].strUserName , [imp_emp].[nUserID], [Device_sukishi].[DeviceID] , [Device_sukishi].[DeviceName] FROM [hr_scan].[dbo].[tb_reportslist] INNER JOIN [hr_scan].[dbo].[imp_emp] ON tb_reportslist.nUserID = imp_emp.[nUserID] INNER JOIN [hr_scan].[dbo].[Device_sukishi] ON tb_reportslist.nDeviceID = Device_sukishi.[DeviceID]
WHERE (CONVERT(date, tb_reportslist.dtDateTime)) BETWEEN '02-02-2015' AND '02-03-2015' AND tb_reportslist.nUserID = '571893' AND (nEvent NOT IN ('23')) order by dtDateTime
select * from tb_reporstlist
inner join
(select min(dtDateTime) as min_in_minute from tb_reporstlist group by CONVERT(VARCHAR(16),dtDateTime,20)) as tmp_tb
on tmp_tb.min_in_minute=tb_reporstlist.dtDateTime