忘记的时候就翻阅翻阅吧~~

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. 好记性不如烂笔头-linux学习笔记1

    好记性不如烂笔头-linux学习笔记1 linux的文件系统有ext2,ext3,ext4,目前主流是ext4 linux主要用于服务器级别的操作系统,安装时需要至少2个分区 一个是交换分区,swap ...

  3. 好记性不如烂笔头-Mysql查找如何判断字段是否包含某个字符串

    好记性不如烂笔头-Mysql查找如何判断字段是否包含某个字符串 利用mysql 字符串函数 find_in_set(); SELECT * FROM users WHERE find_in_set(' ...

  4. [nodejs]修改全局包位置,修复npm安装全局模块命令失效。好记性不如烂笔头

    修复npm -g 全局安装命令失效,好的吧不得不承认,好记性不如烂笔头,我居然会忘记方法哈哈哈 Linux安装nodejs sudo apt install node sudo apt install ...

  5. Common lang一些边界方法总结(好记性不如烂笔头,需要慢慢积累).一定要利用好现有的轮子,例如Apache common与Google Guava

    好记性真是不如烂笔头啊!!!! 如下代码: List<String> list = new ArrayList<String>(); list.add("1" ...

  6. SQL语句笔记/好记性不如烂笔头/持续更新

    常用的增删改查操作,针对库,表,字段,记录分类有助于记忆,当然熟能生巧,还是需要多多实操 库操作 删除库 drop database dbx; 列出所有库 show databases; 切换库 us ...

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

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

  8. sql linq lambda 对比

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

  9. 好记性不如烂笔头-linux学习笔记5mysql主从复制

    mysql主从复制的原理 mysql master服务器,开启bin-log日志,开启IO线程 slave服务器,开启IO线程,开启SQL线程(执行SQL) 1)slave服务器,通过授权用户开启IO ...

随机推荐

  1. 如何初始化一个iOS原生地图

    /** 初始化一个mapView  需导入 #import <MapKit/MapKit.h> - returns: 返回一个mapView对象 */ mapView = [[MKMapV ...

  2. 揭秘TPM安全芯片技术及加密应用

    揭秘TPM安全芯片技术及加密应用 首发:http://safe.it168.com/a2012/0912/1396/000001396884.shtml 从2003年开始,重要数据丢失已经成为严重的信 ...

  3. C++三大库boost、loki、stlport

    转: STL是一个标准,各商家根据这个标准开发了各自的STL版本.而在这形形色色的STL版本中,SGI STL无疑是最引人瞩目的一个.这当然是因为这个STL产品系出名门,其设计和编写者名单中,Alex ...

  4. (笔记)angular选中变色

  5. 1028 C语言文法

    <程序> ->  <外部声明> |  <程序>  <外部声明> <外部声明>  ->   <函数定义>  |  &l ...

  6. .NET Web开发总结(五)

    7 常用服务器控件 7.1 服务器控件概述 · 服务器控件是指在服务器上执行程序的代码的组件 通常这些服务器控件会提供    给用户一定的界面,  以便用户与服务器之间快速的交互 7.2 HTML 服 ...

  7. angularJS 数组更新时重新排序之解决方案一:这个坑,绕开吧,不跳了……

    今天产品大人发现了一bug,图表数据和数据库总是对不上,原因是当前端更新数组时,angularJS默认对数组进行了排序. // 点击事件:input复选框 $scope.fnClickUpdateAr ...

  8. php获取客户端浏览器以及操作系统信息的方法

    发布:sunday01   来源:net   阅读: 2   [大 中 小] 在较为智能的程序中,php可以获取客户端浏览器及操作系统信息,然后根据浏览器及系统类型,加载不同的页面,以提供更加个性化的 ...

  9. Nginx配置:http重定向,URLRewrite,一个简单框架的配置思路

    一个重定向的应用配置: server { listen       8000; server_name  localhost; root F:/home/projects/test; index   ...

  10. 第五节:什么导致Finalize方法被调用

    Finalize方法在垃圾回收结束时被调用,下面有5种事件会导致开始垃圾回收 1.第0代已满    第0代已满,垃圾回收会自动开始.该事件是目前导致Finalize方法被调用的最常见的一种方式,因为虽 ...