编写SQL查询以按特定顺序显示结果

时间:2015-10-31 18:42:46

标签: sql

我有这张桌子

+----+--------+------------+-----------+
| Id | day_id | subject_id | period_Id |
+----+--------+------------+-----------+
| 1  | 1      | 1          | 1         |
| 2  | 1      | 2          | 2         |
| 8  | 2      | 6          | 1         |
| 9  | 2      | 7          | 2         |
| 15 | 3      | 3          | 1         |
| 16 | 3      | 4          | 2         |
| 22 | 4      | 5          | 1         |
| 23 | 4      | 5          | 2         |
| 24 | 4      | 6          | 3         |
| 29 | 5      | 8          | 1         |
| 30 | 5      | 1          | 2         |


to something like this



| Id | day_id | subject_id | period_Id |
| 1  | 1      | 1          | 1         |
| 8  | 2      | 6          | 1         |
| 15 | 3      | 3          | 1         |
| 22 | 4      | 5          | 1         |
| 29 | 5      | 8          | 1         |
| 2  | 1      | 2          | 2         |
| 2  | 1      | 2          | 2         |
| 16 | 3      | 4          | 2         |
| 23 | 4      | 5          | 2         |
| 30 | 5      | 1          | 2         |
+----+--------+------------+-----------+

所以,我想每天选择一个不同主题的时期,这样做几周。所以在选择所有受试者之前,第一个受试者剂量才会到来。

1 个答案:

答案 0 :(得分:0)

您可以先Dim di As New DirectoryInfo(path) Dim lastfile As FileInfo If di.Exists Then lastfile = di.GetFiles("*.jpg", SearchOption.TopDirectoryOnly) _ .Where(Function(f) f.Length > 20000) _ .OrderByDescending(Function(f) f.LastWriteTime) _ .FirstOrDefault(Nothing) If Not IsNothing(lastfile) Then 'Work with file here and hopefully not throw an exception. End If End If period_id然后再ORDER BY

day_id

LiveDemo