首页 > 数据库 >SQL、LINQ、Lambda对照表

SQL、LINQ、Lambda对照表

时间:2023-01-30 17:25:41浏览次数:47  
标签:pr JobTitle Employees LINQ SQL new Lambda SELECT ProductID

SQL、LINQ、Lambda对照表

SQLLINQLambda
SELECT * FROM Employee from e in Employees select e Employees.Select ()
SELECT e.LoginID,e.JobTitle FROM Employee AS e from e in Employees select new Employees.Select ( e => new{LoginID = e.LoginID,JobTitle = e.JobTitle} )
SELECT e.LoginID AS ID, e.JobTitle AS Title FROM Employee AS e from e in Employees select new Employees.Select (e => new{ID = e.LoginID,Title = e.JobTitle } )
SELECT DISTINCT e.JobTitle FROM Employee AS e (from e in Employees select e.JobTitle).Distinct() Employees.Select (e => e.JobTitle) .Distinct ()
SELECT e.* FROM 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 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 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 Employee AS e ORDER BY e.NationalIDNumber from e in Employees orderby e.NationalIDNumber select e Employees.OrderBy (e => e.NationalIDNumber)
SELECT e.* FROM 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 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 Employee AS e   Employees.Sum(e => e.VacationHours);
SELECT COUNT(*) FROM Employee AS e   Employees.Count();
SELECT SUM(e.VacationHours) AS TotalVacations,e.JobTitle FROM Employee AS e GROUP BY e.JobTitle from e in Employees group e by e.JobTitle into g select new 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 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 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 Product AS p,ProductReview AS pr from p in Products from pr in ProductReviews select new Products.SelectMany (p => ProductReviews,(p, pr) =>new{ p = p, pr = pr})
SELECT * FROM Product AS p INNER JOIN ProductReview AS pr ON p.ProductID = pr.ProductID from p in Products join pr in ProductReviews on p.ProductID equals pr.ProductID select new Products.Join (ProductReviews, p => p.ProductID,pr => pr.ProductID, (p, pr) =>new{p = p,pr = pr})
SELECT * FROM Product AS p INNER JOIN 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 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 Product AS p LEFT OUTER JOIN 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 Products.GroupJoin (ProductReviews, p => p.ProductID,pr => pr.ProductID,(p, prodrev) => new{p = p,prodrev = prodrev })
SELECT p.ProductID AS ID FROM Product AS p UNION SELECT pr.ProductReviewID FROM 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 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 [Product] AS p WHERE p.ProductID IN (SELECT pr.ProductID FROM [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)

标签:pr,JobTitle,Employees,LINQ,SQL,new,Lambda,SELECT,ProductID
From: https://www.cnblogs.com/roboot/p/17076693.html

相关文章

  • SQL Server 安装、配置、迁移 三
    本片博文记录数据迁移。两台电脑,一台IP地址为:10.15.66.168,有名为TestprgDB的数据库,另一台IP地址10.15.66.169,无数据库。本次任务目的为把168电脑的数据库拷贝到169电脑。......
  • Sql语句的执行数据是什么?
    SQLSelect语句完整的执行顺序:1、from子句组装来自不同数据源的数据;2、where子句基于指定的条件对记录行进行筛选;3、groupby子句将数据划分为多个分组;4、使用聚集函数......
  • mysql8.0远程访问配置
    mysql8.0远程访问配置一、修改bind-address查找配置文件my.confwhichmysql/usr/bin/mysql--verbose--help|grep-A1'Defaultoptions'vimy.cnfbind-addres......
  • 【Amadeus原创】MySQL8设置root用户远程访问
    1.查询当前root状态,默认root的host是localhostusemysql;selectuser,hostfromuser;2.updateroot的host为%updateusersethost='%'whereuser='root';3.检查客......
  • SQL Server 安装、配置、迁移 二
    本篇博客记录网络配置。本机IP地址:10.15.66.169打开配置界面,如图所示设置TCP/IP为Enabled。双击TCP/IP,出现TCP/IPProperties窗口。选择一个指向本......
  • mysqldump 造成阻塞问题
    备份命令点击查看代码mysqldump-hxxxx-xxxx-P${PORT}-p${Pass}-R-e--triggers--master-data=2--single-transaction--set-gtid-purged=OFF--skip-add-drop......
  • 15.1 SQL Server创建LOGIN(登录)
    SQLServer创建LOGIN(登录)目录SQLServer创建LOGIN(登录)简介示例SQLServerCREATELOGIN语句更多选项CHECK_POLICY选项CHECK_EXPIRATION选项MUST_CHANGE选项从Windows域帐......
  • centos7.9离线安装mysql5.7.40(本文使用initialize-insecure安装方法)
    centos7.9离线安装mysql5.7.40(本文使用initialize-insecure安装方法)一、卸载CentOS7系统自带mariadb#查看系统自带的Mariadb[root@NIWAY-190~]#rpm-qa|grepmariadbm......
  • Servlet+MySQL
    前后端调通后可以把数据存到数据库里了1.下载并配置SQLWindows中MySQL8详细安装教程2.netstart/stopmysql启动/关闭mysql,在管理员身份下运行3.mysql的可视化软件......
  • 通过 explain 关键字对sql进行优化
    在select语句之前增加explain关键字,MySQL会在查询上设置一个标记,执行查询时,会返回执行计划的信息,而不是执行这条SQL(如果from中包含子查询,仍会执行该子查询,将结果放......