SQL

LINQ

Lambda

SELECT *FROM HumanResources.Employee

from e in Employees

select e

Employees .Select (e => e)

SELECT e.LoginID, e.JobTitle

FROM HumanResources.Employee AS e

from e in Employees

select new {e.LoginID, e.JobTitle}

Employees.Select (

      e => new {

            LoginID
= e.LoginID, 

            JobTitle
= e.JobTitle

         }

   )

SELECT e.LoginID AS ID, e.JobTitle AS
Title

FROM HumanResources.Employee AS e

from e in Employees

select new {ID = e.LoginID, Title =
e.JobTitle}

Employees.Select (

      e => new 

         {

            ID =
e.LoginID, 

            Title
= e.JobTitle

         }

   )

SELECT DISTINCT e.JobTitle

FROM HumanResources.Employee AS e

(from e in Employees

select e.JobTitle).Distinct()

Employees

   .Select (e => e.JobTitle)

   .Distinct ()

SELECT e.*

FROM HumanResources.Employee AS e

WHERE e.LoginID = 'test'

from e in Employees

where e.LoginID == "test"

select e

Employees

   .Where (e => (e.LoginID == "test"))

SELECT e.*

FROM HumanResources.Employee AS e

WHERE e.LoginID = 'test' AND
e.SalariedFlag = 1

from e in Employees

where e.LoginID == "test"
&& e.SalariedFlag

select e

Employees

   .Where (e => ((e.LoginID == "test") &&
e.SalariedFlag))

SELECT e.* FROM HumanResources.Employee
AS e

WHERE e.VacationHours >= 2 AND
e.VacationHours <= 10

from e in Employees

where e.VacationHours >= 2 &&
e.VacationHours <= 10

select e

Employees

   .Where (e => (((Int32)(e.VacationHours) >= 2) &&
((Int32)(e.VacationHours) <= 10)))

SELECT e.* FROM HumanResources.Employee
AS e

ORDER BY e.NationalIDNumber

from e in Employees

orderby e.NationalIDNumber

select e

Employees

   .OrderBy (e => e.NationalIDNumber)

SELECT e.* FROM HumanResources.Employee
AS e

ORDER BY e.HireDate DESC,
e.NationalIDNumber

from e in Employees

orderby e.HireDate descending,
e.NationalIDNumber

select e

Employees

   .OrderByDescending (e => e.HireDate)

   .ThenBy (e => e.NationalIDNumber)

SELECT e.* FROM HumanResources.Employee
AS e

WHERE e.JobTitle LIKE 'Vice%' OR
SUBSTRING(e.JobTitle, 0, 3) = 'Pro'

from e in Employees

where
e.JobTitle.StartsWith("Vice") || e.JobTitle.Substring(0, 3) ==
"Pro"

select e

Employees

   .Where (e => (e.JobTitle.StartsWith ("Vice") ||
(e.JobTitle.Substring (0, 3) == "Pro")))

SELECT SUM(e.VacationHours)

FROM HumanResources.Employee AS e

Employees.Sum(e => e.VacationHours);

SELECT COUNT(*) FROM
HumanResources.Employee AS e

Employees.Count();

SELECT SUM(e.VacationHours) AS
TotalVacations, e.JobTitle

FROM HumanResources.Employee AS e

GROUP BY e.JobTitle

from e in Employees

group e by e.JobTitle into g

select new {JobTitle = g.Key,
TotalVacations = g.Sum(e => e.VacationHours)}

Employees

   .GroupBy (e => e.JobTitle)

   .Select (

      g => new 

         {

            JobTitle
= g.Key, 

            TotalVacations
= g.Sum (e => (Int32)(e.VacationHours))

         }

   )

SELECT e.JobTitle, SUM(e.VacationHours)
AS TotalVacations

FROM HumanResources.Employee AS e

GROUP BY e.JobTitle

HAVING e.COUNT(*) > 2

from e in Employees

group e by e.JobTitle into g

where g.Count() > 2

select new {JobTitle = g.Key,
TotalVacations = g.Sum(e => e.VacationHours)}

Employees

   .GroupBy (e => e.JobTitle)

   .Where (g => (g.Count () > 2))

   .Select (

      g => 

         new 

         {

            JobTitle
= g.Key, 

            TotalVacations
= g.Sum (e => (Int32)(e.VacationHours))

         }

   )

SELECT *

FROM Production.Product AS p,
Production.ProductReview AS pr

from p in Products

from pr in ProductReviews

select new {p, pr}

Products

   .SelectMany (

      p => ProductReviews, 

      (p, pr) => 

         new 

         {

            p =
p, 

            pr =
pr

         }

   )

SELECT *

FROM Production.Product AS p

INNER JOIN Production.ProductReview AS
pr ON p.ProductID = pr.ProductID

from p in Products

join pr in ProductReviews on p.ProductID
equals pr.ProductID

select new {p, pr}

Products

   .Join (

      ProductReviews, 

      p => p.ProductID, 

      pr => pr.ProductID, 

      (p, pr) => 

         new 

         {

            p =
p, 

            pr =
pr

         }

   )

SELECT *

FROM Production.Product AS p

INNER JOIN Production.ProductCostHistory
AS pch ON p.ProductID = pch.ProductID AND p.SellStartDate = pch.StartDate

from p in Products

join pch in ProductCostHistories on new
{p.ProductID, StartDate = p.SellStartDate} equals new {pch.ProductID,
StartDate = pch.StartDate}

select new {p, pch}

Products

   .Join (

      ProductCostHistories, 

      p => 

         new 

         {

            ProductID
= p.ProductID, 

            StartDate
= p.SellStartDate

         }, 

      pch => 

         new 

         {

            ProductID
= pch.ProductID, 

            StartDate
= pch.StartDate

         }, 

      (p, pch) => 

         new 

         {

            p =
p, 

            pch =
pch

         }

   )

SELECT *

FROM Production.Product AS p

LEFT OUTER JOIN Production.ProductReview
AS pr ON p.ProductID = pr.ProductID

from p in Products

join pr in ProductReviews on p.ProductID
equals pr.ProductID

into prodrev

select new {p, prodrev}

Products

   .GroupJoin (

      ProductReviews, 

      p => p.ProductID, 

      pr => pr.ProductID, 

      (p, prodrev) => 

         new 

         {

            p =
p, 

            prodrev
= prodrev

         }

   )

SELECT p.ProductID AS ID

FROM Production.Product AS p

UNION

SELECT pr.ProductReviewID

FROM Production.ProductReview AS pr

(from p in Products

select new {ID = p.ProductID}).Union(

from pr in ProductReviews

select new {ID = pr.ProductReviewID})

Products

   .Select (

      p => 

         new 

         {

            ID =
p.ProductID

         }

   )

   .Union (

      ProductReviews

         .Select (

            pr
=> 

              
new 

              
{

                  ID
= pr.ProductReviewID

              
}

         )

   )

SELECT TOP (10) *

FROM Production.Product AS p

WHERE p.StandardCost < 100

(from p in Products

where p.StandardCost < 100

select p).Take(10)

Products

   .Where (p => (p.StandardCost < 100))

   .Take (10)

SELECT *

FROM [Production].[Product] AS p

WHERE p.ProductID IN(

SELECT
pr.ProductID

FROM
[Production].[ProductReview] AS [pr]

WHERE
pr.[Rating] = 5

)

from p in Products

where (from pr in ProductReviews

where pr.Rating == 5

select
pr.ProductID).Contains(p.ProductID)

select p

Products

   .Where (

      p => 

         ProductReviews

            .Where
(pr => (pr.Rating == 5))

            .Select
(pr => pr.ProductID)

            .Contains
(p.ProductID)

   )

SQL-LINQ-Lambda语法对照的更多相关文章

  1. SQL,LINQ,Lambda语法对照图(转载)

    如果你熟悉SQL语句,当使用LINQ时,会有似曾相识的感觉.但又略有不同.下面是SQL和LINQ,Lambda语法对照图 SQL LINQ Lambda SELECT * FROM HumanReso ...

  2. SQL,Linq,Lambda之间的转换练习

    1.查询Student表中的所有记录的Sname.Ssex和Class列. SQL:select sname,ssex,class from Students linq:from s in Stude ...

  3. sql linq lambda 对比

    . 查询Student表中的所有记录的Sname.Ssex和Class列. select sname,ssex,class from student Linq: from s in Students ...

  4. SQL-LINQ-Lambda 语法对照

    SQL LINQ Lambda  SELECT *FROM Employees from e in Employees  select e Employees .Select (e => e)  ...

  5. SQL/LINQ/Lamda 写法[转发]

    SQL LINQ Lambda SELECT * FROM HumanResources.Employee from e in Employees select e Employees   .Sele ...

  6. SQL Linq lamda区别

    SQL LINQ Lambda SELECT * FROM HumanResources.Employee from e in Employees select e Employees   .Sele ...

  7. SQL/LINQ/Lamda

    SQL LINQ Lambda SELECT * FROM HumanResources.Employee from e in Employees select e Employees   .Sele ...

  8. SQL-LINQ-Lambda语法对照,好记性不如烂笔头

    忘记的时候就翻阅翻阅吧~~ SQL LINQ Lambda SELECT *FROM HumanResources.Employee from e in Employees select e Empl ...

  9. LINQ之路 4:LINQ方法语法

    书写LINQ查询时又两种语法可供选择:方法语法(Fluent Syntax)和查询语法(Query Expression). LINQ方法语法是非常灵活和重要的,我们在这里将描述使用链接查询运算符的方 ...

随机推荐

  1. 逻辑回归:使用SGD(Stochastic Gradient Descent)进行大规模机器学习

    Mahout学习算法训练模型 mahout提供了许多分类算法,但许多被设计来处理非常大的数据集,因此可能会有点麻烦.另一方面,有些很容易上手,因为,虽然依然可扩展性,它们具有低开销小的数据集.这样一个 ...

  2. UVA 11825 Hackers’ Crackdown(集合动态规划 子集枚举)

    Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...

  3. php日期处理

    $datetime=strtotime(date("Y-m-d",time()));//获取当前日期并转换成时间戳 $datetime=$datetime+86400;//在时间戳 ...

  4. 深入了解jquery中的键盘事件

    很多时候,我们需要获取用户的键盘事件,下面就一起来看看jquery是如何操作键盘事件的. 一.首先需要知道的是: 1.keydown() keydown事件会在键盘按下时触发. 2.keyup() k ...

  5. jQuery 源码细读 -- $.Callbacks

    $.Callbacks 是 jQuery 提供的可以方便地处理各种回调(callback)列表的类,其源代码是闭包的经典实现. 基本原理就是通过在闭包环境内保存一个 list = [] 数组用于存储回 ...

  6. jsp 页面通过jq处理默认 选中的项 数据是通过遍历显示

    jsp页面循环显示里面是<a></a>或者<input>  id 以什么开头的id,然后当你点击那个的时候就在那个上面添加样式 <div> <di ...

  7. Svn与Git的区别

    把第一条理解到位思想到位了做起来才会有的放矢,其他几条都是用的时候才能体会到 1) 最核心的区别Git是分布式的,而Svn不是分布的.能理解这点,上手会很容易,声明一点Git并不是目前唯一的分布式版本 ...

  8. http://src.chromium.org/svn/ 定制chrome浏览器教程及源码

    chromium 官网登不进去,最近在学习chrome插件制作,网上教程很多大多没有源码 其实作为开源软件 官方提供了全部源码地址:http://src.chromium.org/svn/ PRESU ...

  9. 为何要fork()两次来避免产生僵尸进程??

    最近安装书上说的,开始搞多进程了..看到了一个好帖子,学习学习 http://blog.sina.com.cn/s/blog_9f1496990100y420.html 首先我们要明白,为什么要避免僵 ...

  10. 关于Keil的安装与注册

    由于前一段时间一直在做关于stm32f407的相关内容,于是安装的Keil是MDK5,最近一阵子想再看看51单片机以前没有做过的内容,就要再安装一个Keil C51,结果就不可避免的遇到了两个软件必须 ...