本帖最后由 hessen 于 2020-7-8 17:36 编辑
取各个单位最后一次填写的那笔记录,这里是SQL示例,可以直接写在快表中。如果不会联系我。
- CREATE TABLE [dbo].[T_565](
- [ID] [varchar](50) NULL,
- [CUID] [varchar](50) NULL,
- [CDID] [varchar](50) NULL,
- [CUNAME] [nvarchar](255) NULL,
- [CDATE] [datetime] NULL,
- [EUID] [varchar](50) NULL,
- [EUNAME] [nvarchar](255) NULL,
- [EDATE] [datetime] NULL,
- [WFID] [varchar](50) NULL,
- [REPORTLOCK] [bit] NULL,
- [REPORTEDIT] [bit] NULL,
- [F_15222] [varchar](255) NULL,
- [F_15223] [datetime] NULL
- ) ON [PRIMARY]
- GO
- INSERT [dbo].[T_565] ([ID], [CUID], [CDID], [CUNAME], [CDATE], [EUID], [EUNAME], [EDATE], [WFID], [REPORTLOCK], [REPORTEDIT], [F_15222], [F_15223]) VALUES (N'1b104f8e-2cc6-47e7-845f-3222fadf477b', N'0e6c2110-37a6-40e0-8fd9-a82edad11bae', N'91c8f637-37a4-4117-992a-d5c425418cd8', N'超级管理员', CAST(N'2020-07-08T15:49:53.977' AS DateTime), NULL, NULL, NULL, N'', NULL, NULL, N'1', CAST(N'2020-07-08T00:00:00.000' AS DateTime))
- INSERT [dbo].[T_565] ([ID], [CUID], [CDID], [CUNAME], [CDATE], [EUID], [EUNAME], [EDATE], [WFID], [REPORTLOCK], [REPORTEDIT], [F_15222], [F_15223]) VALUES (N'b2a6a811-c5f9-4f48-8fa5-76b1d8335a5c', N'0e6c2110-37a6-40e0-8fd9-a82edad11bae', N'91c8f637-37a4-4117-992a-d5c425418cd8', N'超级管理员', CAST(N'2020-07-08T15:49:56.043' AS DateTime), NULL, NULL, NULL, N'', NULL, NULL, N'2', CAST(N'2020-07-08T00:00:00.000' AS DateTime))
- INSERT [dbo].[T_565] ([ID], [CUID], [CDID], [CUNAME], [CDATE], [EUID], [EUNAME], [EDATE], [WFID], [REPORTLOCK], [REPORTEDIT], [F_15222], [F_15223]) VALUES (N'437a7295-7ada-4320-9646-e9b307c380f4', N'0e6c2110-37a6-40e0-8fd9-a82edad11bae', N'91c8f637-37a4-4117-992a-d5c425418cd8', N'超级管理员', CAST(N'2020-07-08T15:49:57.890' AS DateTime), NULL, NULL, NULL, N'', NULL, NULL, N'3', CAST(N'2020-07-08T00:00:00.000' AS DateTime))
- INSERT [dbo].[T_565] ([ID], [CUID], [CDID], [CUNAME], [CDATE], [EUID], [EUNAME], [EDATE], [WFID], [REPORTLOCK], [REPORTEDIT], [F_15222], [F_15223]) VALUES (N'15bd21e3-56aa-489a-bf3d-de54d53136d6', N'0e6c2110-37a6-40e0-8fd9-a82edad11bae', N'91c8f637-37a4-4117-992a-d5c425418cd8', N'超级管理员', CAST(N'2020-07-08T15:49:59.920' AS DateTime), NULL, NULL, NULL, N'', NULL, NULL, N'4', CAST(N'2020-07-08T00:00:00.000' AS DateTime))
- INSERT [dbo].[T_565] ([ID], [CUID], [CDID], [CUNAME], [CDATE], [EUID], [EUNAME], [EDATE], [WFID], [REPORTLOCK], [REPORTEDIT], [F_15222], [F_15223]) VALUES (N'e1ce96e0-f731-455b-8a1a-db2ab45a3265', N'0e6c2110-37a6-40e0-8fd9-a82edad11bae', N'91c8f637-37a4-4117-992a-d5c425418cd8', N'超级管理员', CAST(N'2020-07-08T15:50:01.997' AS DateTime), NULL, NULL, NULL, N'', NULL, NULL, N'5', CAST(N'2020-07-08T00:00:00.000' AS DateTime))
- INSERT [dbo].[T_565] ([ID], [CUID], [CDID], [CUNAME], [CDATE], [EUID], [EUNAME], [EDATE], [WFID], [REPORTLOCK], [REPORTEDIT], [F_15222], [F_15223]) VALUES (N'ad4147d8-c5e3-4ea8-ad1f-d9410ea47fa7', N'0e6c2110-37a6-40e0-8fd9-a82edad11bae', N'91c8f637-37a4-4117-992a-d5c425418cd8', N'超级管理员', CAST(N'2020-07-08T15:50:03.780' AS DateTime), NULL, NULL, NULL, N'', NULL, NULL, N'6', CAST(N'2020-07-08T00:00:00.000' AS DateTime))
- INSERT [dbo].[T_565] ([ID], [CUID], [CDID], [CUNAME], [CDATE], [EUID], [EUNAME], [EDATE], [WFID], [REPORTLOCK], [REPORTEDIT], [F_15222], [F_15223]) VALUES (N'ea9b76eb-b47f-4c2c-8bce-08b671cc6392', N'0e6c2110-37a6-40e0-8fd9-a82edad11bae', N'91c8f637-37a4-4117-992a-d5c425418cd8', N'超级管理员', CAST(N'2020-07-08T15:51:02.547' AS DateTime), NULL, NULL, NULL, N'', NULL, NULL, N'1', CAST(N'2020-07-07T00:00:00.000' AS DateTime))
- INSERT [dbo].[T_565] ([ID], [CUID], [CDID], [CUNAME], [CDATE], [EUID], [EUNAME], [EDATE], [WFID], [REPORTLOCK], [REPORTEDIT], [F_15222], [F_15223]) VALUES (N'c70e67b6-3777-411c-a795-da21a3f50087', N'0e6c2110-37a6-40e0-8fd9-a82edad11bae', N'91c8f637-37a4-4117-992a-d5c425418cd8', N'超级管理员', CAST(N'2020-07-08T15:51:04.167' AS DateTime), NULL, NULL, NULL, N'', NULL, NULL, N'2', CAST(N'2020-07-07T00:00:00.000' AS DateTime))
- INSERT [dbo].[T_565] ([ID], [CUID], [CDID], [CUNAME], [CDATE], [EUID], [EUNAME], [EDATE], [WFID], [REPORTLOCK], [REPORTEDIT], [F_15222], [F_15223]) VALUES (N'806b625f-bbec-4415-84da-e03838ba89ae', N'0e6c2110-37a6-40e0-8fd9-a82edad11bae', N'91c8f637-37a4-4117-992a-d5c425418cd8', N'超级管理员', CAST(N'2020-07-08T15:51:05.560' AS DateTime), NULL, NULL, NULL, N'', NULL, NULL, N'3', CAST(N'2020-07-07T00:00:00.000' AS DateTime))
- INSERT [dbo].[T_565] ([ID], [CUID], [CDID], [CUNAME], [CDATE], [EUID], [EUNAME], [EDATE], [WFID], [REPORTLOCK], [REPORTEDIT], [F_15222], [F_15223]) VALUES (N'6ba3047d-dab2-4954-a501-e01e7bc64c6c', N'0e6c2110-37a6-40e0-8fd9-a82edad11bae', N'91c8f637-37a4-4117-992a-d5c425418cd8', N'超级管理员', CAST(N'2020-07-08T15:51:06.727' AS DateTime), NULL, NULL, NULL, N'', NULL, NULL, N'4', CAST(N'2020-07-07T00:00:00.000' AS DateTime))
- INSERT [dbo].[T_565] ([ID], [CUID], [CDID], [CUNAME], [CDATE], [EUID], [EUNAME], [EDATE], [WFID], [REPORTLOCK], [REPORTEDIT], [F_15222], [F_15223]) VALUES (N'bef3b2a1-fbda-4be5-9184-fbe0e4e095d3', N'0e6c2110-37a6-40e0-8fd9-a82edad11bae', N'91c8f637-37a4-4117-992a-d5c425418cd8', N'超级管理员', CAST(N'2020-07-08T15:51:07.860' AS DateTime), NULL, NULL, NULL, N'', NULL, NULL, N'5', CAST(N'2020-07-07T00:00:00.000' AS DateTime))
- INSERT [dbo].[T_565] ([ID], [CUID], [CDID], [CUNAME], [CDATE], [EUID], [EUNAME], [EDATE], [WFID], [REPORTLOCK], [REPORTEDIT], [F_15222], [F_15223]) VALUES (N'50d03b46-2aba-49fe-b0e8-f958aac828c6', N'0e6c2110-37a6-40e0-8fd9-a82edad11bae', N'91c8f637-37a4-4117-992a-d5c425418cd8', N'超级管理员', CAST(N'2020-07-08T15:51:09.020' AS DateTime), NULL, NULL, NULL, N'', NULL, NULL, N'6', CAST(N'2020-07-07T00:00:00.000' AS DateTime))
- INSERT [dbo].[T_565] ([ID], [CUID], [CDID], [CUNAME], [CDATE], [EUID], [EUNAME], [EDATE], [WFID], [REPORTLOCK], [REPORTEDIT], [F_15222], [F_15223]) VALUES (N'f96bdaed-b48a-49ae-aff3-b249852024b0', N'0e6c2110-37a6-40e0-8fd9-a82edad11bae', N'91c8f637-37a4-4117-992a-d5c425418cd8', N'超级管理员', CAST(N'2020-07-08T15:51:10.147' AS DateTime), NULL, NULL, NULL, N'', NULL, NULL, N'7', CAST(N'2020-07-07T00:00:00.000' AS DateTime))
- INSERT [dbo].[T_565] ([ID], [CUID], [CDID], [CUNAME], [CDATE], [EUID], [EUNAME], [EDATE], [WFID], [REPORTLOCK], [REPORTEDIT], [F_15222], [F_15223]) VALUES (N'7ab50ed3-6b06-440b-b3ca-44aefa3d36ec', N'0e6c2110-37a6-40e0-8fd9-a82edad11bae', N'91c8f637-37a4-4117-992a-d5c425418cd8', N'超级管理员', CAST(N'2020-07-08T15:51:11.243' AS DateTime), NULL, NULL, NULL, N'', NULL, NULL, N'8', CAST(N'2020-07-07T00:00:00.000' AS DateTime))
- INSERT [dbo].[T_565] ([ID], [CUID], [CDID], [CUNAME], [CDATE], [EUID], [EUNAME], [EDATE], [WFID], [REPORTLOCK], [REPORTEDIT], [F_15222], [F_15223]) VALUES (N'06e12bd9-be45-4001-8816-13c8f15e6f91', N'0e6c2110-37a6-40e0-8fd9-a82edad11bae', N'91c8f637-37a4-4117-992a-d5c425418cd8', N'超级管理员', CAST(N'2020-07-08T15:51:12.330' AS DateTime), NULL, NULL, NULL, N'', NULL, NULL, N'9', CAST(N'2020-07-07T00:00:00.000' AS DateTime))
- --数据准备完毕下面查询
- WITH C AS(
- SELECT ROW_NUMBER() OVER(PARTITION BY F_15222 ORDER BY F_15223 DESC) AS NO,F_15222 AS A,F_15223 AS B FROM T_565
- )
- SELECT A,B FROM C WHERE NO = 1 ORDER BY B
- --得到最近的数据
复制代码
效果如下图:
|
|
hessen