1、 查询Student表中的所有记录的Sname、Ssex和Class列。(select sname,ssex,class from student)
Students.Select(s=> new { sname=>s.sname,ssex=>s.ssex, class=>s.class})
linq:from s in Students select new{s.sname, }

2.查询教师所有的单位即不重复的Depart列。select distinct depart from teacher
teachers.distinct().Select(s=>s.depart)
linq: from s in teachers.Distinct() select s.depart

3、 查询Student表的所有记录。select * from Student
student.Select(s=>s)
linq: from s in student select s;

4、 查询Score表中成绩在60到80之间的所有记录。 select * from score where grages bewteen 60 and 80
score.Where(s=>(s.grages>60 && s.grages<80) );
linq: from s in score where s.grages>60 && s.grages<80 select s;

5、 查询Score表中成绩为85,86或88的记录。select * from score where grages in (85,86,88)
linq: from s in Score Where ( new decimal[] {85,86,88}.Contains(s.grage))
Scores.Where( s => new Decimal[] {85,86,88}.Contains(s.grage))

6、 查询Student表中"95031"班或性别为"女"的同学记录。select * from student where class ='95031' or ssex= '女'
student.Where(s=> (s.class=="95031" || s.sex="女"))
from s in student where s.class=="" || s.sex=="" select s;

7、 以Class降序查询Student表的所有记录。 select * from student order by Class DESC
student.OrderByDescing(s=> s.Class)

from s in student order by s.class descending select s;

8、 以Cno升序、Degree降序查询Score表的所有记录。select * from Score order by cno asc and grage desc
score.OrderByDescing(s=>s.grage).OrderBy(s=>s.cno);

from s in score order by s.grage descending order by s.cno ascending select s;

9、 查询"95031"班的学生人数。select count(*) from Students where class='95031'
students.Select(s=>s.class=='95031').Count();
///students.Where(s=>s.class=='').Select(s=>s).Count();

10、查询Score表中的最高分的学生学号和课程号。

11、查询'3-105'号课程的平均分。select avg(grage) from score where cno='3-105'
score.where(s=>s.con=="3-105").Select(s=>s.grage).Avgage();

12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。
select avg(degree) from score where cno like '3%' group by Cno having count(*)>=5

linq: from s in score where s.con.StartWith("3") group s by s.Cno into cc where cc.count>5
select cc.Avgage(s=>s.grage)

13、查询最低分大于70,最高分小于90的Sno列。select Sno from score group by Sno having min(grage)>70 and
max(grage)<90
linq: from s in score group s by s.sno into cc where cc.min(grage)>70 && cc.Max(grage)<90
select new {sno =>cc.key}

lambda:
scores.GroupBy(s=>s.sno).Where(ss=> ( (ss.Min(cc=>cc.grage)>70) && (ss.Max(cc=>cc.grage)<90 )))
.select(ss=> new {sno=>ss.key})

14、查询所有学生的Sname、Cno和Degree列。
select s.sname,sc.cno,sc.degree from student s,score sc where s.sno = sc.sno

from s in Student join sc in score on s.sno=sc.sno
select new {s.sname,sc.cno, sc.degree}

lambda: Student.join(scores,s=>s.sname,
sc=>sc.cno,
(s,sc)=> new{ sname =s.sname, cno=sc.cno, degree=sc.degree })

//释放资源 .Dispose();
------------------------------------------------------------
.skip(1).Take(4) Skip 上面这段语句的意思是从第二条数据开始显示4条
AppendAndWhere //附加AND查询条件 JoinOnAndWhere //joinon筛选条

Any(): 判断集合中是否有元素满足某一条件
仅返回没有订单的客户:var q =from c in db.Customers where !c.Orders.Any() select c;

All(): 判断集合中所有元素是否都满足某一条件。
var q =from c in db.Customers where c.Orders.All(o => o.ShipCity == c.City) select c;
语句描述:这个例子返回所有订单都运往其所在城市的客户或未下订单的客户。

Contains() :用于判断集合中是否包含有某一元素

Concat(连接): 连接不同的集合,不会自动过滤相同项
var q = (from c in db.Customers select c.Phone).Concat(from c in db.Customers select c.Fax).Concat(from e in db.Employees select e.HomePhone);
语句描述:返回所有消费者和雇员的电话和传真。

Union ::连接不同的集合,自动过滤相同项;延迟。即是将两个集合进行合并操作,过滤相同的项。

Intersect(相交) :取相交项;延迟。即是获取不同集合的相同项(交集)。
Except (与非) :排除相交项;
.Implicit(隐式) Explicit(显式)

ToArray:将序列转换为数组

ToList:将序列转换为泛型列表
-------------------------------------------------------------

最新文章

  1. maven工程使用spring-boot-devtools进行热部署,更改代码避免重启web容器
  2. 传智博客.NET培训第13季 Ajax教程(共十三季) 学习资源
  3. css实现绝对定位元素居中
  4. C语言,不是从hello world开始
  5. Unieap3.5错误收集
  6. 负MARGIN之讲解
  7. c# List&lt;int&gt; 转 string 以及 string [] 转 List&lt;int&gt;
  8. EXTJS API
  9. PS:改装店收的是友情价,包安装十五个毛主席。
  10. lpr
  11. LINUX 笔记-cp命令
  12. Linux学习--线程概念
  13. Java的运行原理
  14. ReactNative之结合具体示例来看RN中的的Timing动画
  15. Eclipse+Maven整合开发Java项目(一)➣Maven基础环境配置
  16. oracle日常查看
  17. CORS跨域请求
  18. Controller:EOS区块链核心控制器
  19. &lt;转&gt;jmeter(十三)常见问题及解决方法
  20. Camtasia studio8.0破解方法

热门文章

  1. 用Struts2搭建一个登录例子【本人亲测好用】
  2. javascript中 visibility和display的区别
  3. 在使用FireFox浏览器时,经常打开新标签,页面总是不断自动刷新,解决办法
  4. PHP高手进阶-LAMPer技能树
  5. HDU——T 1251 统计难题
  6. 洛谷 P1964 【mc生存】卖东西
  7. TCP的可靠性 窗口滑动 拥塞控制
  8. Fastboot线刷“复活”之刷机心得(三)——错误处理
  9. 程序猿的量化交易之路(13)--Cointrader类图(1)
  10. struts2 结合extjs实现的一个登录实例