sql语句请教
假设现在有一个如下的表id department major class
1 a aa a1
2 a aa a1
3 a cc a2
4 b dd b1
5 b dd b1
6 b dd b1
7 c ee c1
8 c ee c2
9 c ff c3
10 d gg d1
11 d gg d1
现在想要循环输出所有不重复的class,然后还有该class所对应的major和department,sql语句要怎么写?
期望输出如下
a aa a1
a aa a2
b dd b1
c ee c1
c ee c2
c ff c3
d gg d1
本帖最后由 一叶扁舟 于 2014-5-15 21:12 编辑
每个class所对应的major和department是定值吗?
就是说每个相同的class对应的major和department是一样的
select * from table where id in (select min(id) from table group by class)
试试这个吧 一叶扁舟 发表于 2014-5-15 21:15
select * from table where id in (select min(id) from table group by class)
试试这个吧
太棒了,正是想要这样的效果,谢谢!但不知这样的语句用CI的AR应该如何去写呢?
页:
[1]