# SQL技术支持！

0

语文
课程同步
上册
下册
课外辅导
配套试卷
期中
期末
数学
课程同步
课外辅导
配套试卷

语文

1行受影响 | 初学一级 | 园豆：113

0

```  1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Data;
6
7 namespace ConsoleApplication2
8 {
9     class Program
10     {
11         static void Main(string[] args)
12         {
13             DataTable dt = GetDt();
14             IList<Entity> list = GetList(dt);
15             var query = from d in list
16                         group d by d.ChannelName;
17
18             foreach (var v in query)
19             {
20                 Console.WriteLine(v.Key);
21
22                 var query1 = from d1 in v
23                              group d1 by d1.ModuleName;
24
25                 foreach (var v1 in query1)
26                 {
27                     Console.WriteLine("\t{0}", v1.Key);
28
29                     var query2 = from d2 in v1
30                                  group d2 by d2.ProgrameNameOne;
31
32                     foreach (var v2 in query2)
33                     {
34                         Console.WriteLine("\t\t{0}", v2.Key);
35
36                         foreach (var end in v2)
37                         {
38                             if (!string.IsNullOrEmpty(end.ProgrameNameTwo))
39                                 Console.WriteLine("\t\t\t{0}", end.ProgrameNameTwo);
40                         }
41                     }
42                 }
43             }
44
45         }
46
47         /// <summary>
48         /// 获取list集合
49         /// </summary>
50         /// <param name="dt"></param>
51         /// <returns></returns>
52         private static IList<Entity> GetList(DataTable dt)
53         {
54             IList<Entity> list = new List<Entity>();
55             foreach (DataRow dr in dt.Rows)
56             {
57                 Entity model = new Entity();
58                 model.PKID = int.Parse(dr[0].ToString());
59                 model.ChannelName = dr[1].ToString();
60                 model.ModuleName = dr[2].ToString();
61                 model.ProgrameNameOne = dr[3].ToString();
62                 model.ProgrameNameTwo = dr[4].ToString();
64             }
65             return list;
66         }
67
68         /// <summary>
69         /// 模拟数学源
70         /// </summary>
71         /// <returns></returns>
72         private static DataTable GetDt()
73         {
74             DataTable dt = new DataTable();
80
81             dt.Rows.Add(1, "一年级", "语文", "课程同步", "上册");
82             dt.Rows.Add(2, "一年级", "语文", "课程同步", "下册");
83             dt.Rows.Add(3, "一年级", "语文", "课外辅导", null);
84             dt.Rows.Add(4, "一年级", "语文", "配套试卷", "单元");
85             dt.Rows.Add(5, "一年级", "语文", "配套试卷", "其中");
86             dt.Rows.Add(6, "一年级", "语文", "配套试卷", "期末");
87             dt.Rows.Add(7, "一年级", "数学", "课程同步", "上册");
88             dt.Rows.Add(8, "一年级", "数学", "课程同步", "下册");
89             dt.Rows.Add(9, "一年级", "数学", "课外辅导", null);
90             dt.Rows.Add(10, "一年级", "数学", "配套试卷", "单元");
91             dt.Rows.Add(11, "一年级", "数学", "配套试卷", "其中");
92             dt.Rows.Add(12, "一年级", "数学", "配套试卷", "期末");
93             dt.Rows.Add(13, "二年级", "语文", "课程同步", "上册");
94             dt.Rows.Add(14, "二年级", "语文", "课程同步", "下册");
95             dt.Rows.Add(15, "二年级", "语文", "课外辅导", null);
96             dt.Rows.Add(16, "二年级", "语文", "配套试卷", "单元");
97             dt.Rows.Add(17, "二年级", "语文", "配套试卷", "其中");
98             dt.Rows.Add(18, "二年级", "语文", "配套试卷", "期末");
99             return dt;
100         }
101     }
102
103     internal class Entity
104     {
105         public int PKID { get; set; }
106         public string ChannelName { get; set; }
107         public string ModuleName { get; set; }
108         public string ProgrameNameOne { get; set; }
109         public string ProgrameNameTwo { get; set; }
110     }
111 }```

xu_happy_you | 菜鸟二级 |园豆：222 | 2012-05-18 11:30

1行受影响 | 园豆：113 (初学一级) | 2012-05-18 11:48

xu_happy_you | 园豆：222 (菜鸟二级) | 2012-05-18 11:54

@xu_happy_you: 打印出来就行

1行受影响 | 园豆：113 (初学一级) | 2012-05-18 12:25

0

您需要登录以后才能回答，未注册用户请先注册