- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将以下语句放在一起,我知道这很长,最初创建时是在 Microsoft Query 中完成的,因此它不会进行正确的连接。进行连接的最佳方法是什么?我正在形成一个进度数据库,将查询直接拉入 Excel。
SELECT
Company_0.CoaCompanyName
,Company_0.CompanyID
, SopOrder_0.SooOrderDate
, Count(DISTINCT SopOrder_0.SooParentOrderReference) AS 'Orders'
, SUM(CASE WHEN SopOrder_0.SooOrderNumber IS NOT NULL THEN 1 ELSE 0 END) AS 'Order Items'
, SUM(SopOrderItem_0.SoiValue) AS 'Order Value'
,(CASE WHEN SopOrder_0.SooParentOrderReference LIKE 'INT%' THEN 'INT' ELSE 'WEB' END) AS 'OrderType'
,(CASE WHEN Company_0.CompanyID IN (7942127,7950986,7955733,7955922,7956194,9166261,9167003,9167015,9167821,9168185,71108583,153823092,239325930,248936585,484537132,484562257,492867962,497661455) THEN 'Blue'
WHEN Company_0.CompanyID IN (7941326,7942863,7951258,7985610,8054787,8059257,8071540,9165903,9166385,9167199,9167239,9168059,9168092,9168309,9176378,87527213,137281027,141171263,187080272,206550932,206567582,206653611,261731657,291593618,332362604,335570516,335584157,335636738,335780251,337122588,337321409,337495183,338813206,339895994,340298080,345796060,352141359,355461038,367864957,368581219,380483346,388367115,394146462,420408339,422017277,482844312,484535001,490217153,500689836,530081645,626234139,626240584) THEN 'Green'
WHEN Company_0.CompanyID IN (7937292,10245154,12081274,69822571,244700075,348041567,350378220,369621811,492752273,492810572,495589681,497434153,497436315,497447995,497501580,497640064,497687156,524765392,543828284,544700552,577727766) THEN 'InterGroup'
WHEN Company_0.CompanyID IN (390329465,7939077,7939153,7939643,7941067,7941441,7948530,7954220,7954463,7967527,7967564,7967581,7967598,7967615,7967632,7972683,8010930,8055406,8145843,8298176,8555272,8557302,9165068,9165858,9165941,9165990,9166173,9166187,9166221,9166275,9166408,9166733,9166771,9166817,9166839,9167420,9167441,9167462,9167785,9167852,9167909,9168157,9168555,9168579,9168656,9168739,9872539,12079739,12085840,12090519,13801203,18579021,34030102,34324342,34387765,58651641,70893751,75695054,94804172,104968711,124831809,135938287,140557486,155773253,170949925,181601032,181716302,181882963,185256839,191685680,195478063,196446370,196668711,198801097,203101459,217752161,230159704,241060623,246550560,248306594,252917455,272669511,275471863,294618970,302920726,305222885,327567159,328144055,330709733,332849207,337549264,337731848,340242946,340680961,348334040,349629764,350498903,357825478,358320695,362987262,391331042,400869283,401815465,428957939,429336116,432275881,432279597,443630203,450567544,453988169,484512602,484520712,484533033,484534199,484535847,484544428,484545125,484547021,484553137,487900076,491242614,492744710,492787927,492799726,492866923,497444080,497483018,499764323,501511914,502110491,503540613,503636535,504164530,508658401,508888435,508928101,511003520,513859770,517955290,519195801,523016532,527792211,542417909,547466213,549446456,553500528,553903855,557276314,558877342,575056260,591279217,592140130,600576497,602002033,615324116,626695365,633057105) THEN 'RED'
WHEN Company_0.CompanyID IN (7939412,7939655,7941712,8054218,8054544,8054567,8059303,9166056,9168330,94823141,303192985,337650213,340055053,357598514,506835671,512310844,574877608,576590130,603197632) THEN 'Yellow'
ELSE NULL
END) AS 'Cell'
,(CASE
WHEN SopOrderItem.SoiProcessMethod = 0 AND SopOrderItem.SoiReplenishmentOrder = 1 AND SopProduct.SopPrePostPaid = 0 THEN 'Replenishment Pay on Replenishment'
WHEN SopOrderItem.SoiProcessMethod = 0 AND SopOrderItem.SoiReplenishmentOrder = 1 AND SopProduct.SopPrePostPaid <> 0 THEN 'Replenishment Pay on Delivery'
WHEN SopOrderItem.SoiProcessMethod = 0 AND SopOrderItem.SoiReplenishmentOrder = 0 THEN 'Call off'
WHEN SopOrderItem.SoiProcessMethod = 1 THEN 'On Demand'
WHEN SopOrderItem.SoiProcessMethod = 2 THEN 'Personalised'
ELSE 'Service'
END) AS 'OrderMethod'
FROM
SBS.PUB.Company Company_0
, SBS.PUB.SopOrder SopOrder_0
, SBS.PUB.SopOrderItem SopOrderItem_0
, SBS.PUB.SopProduct SopProduct_0
WHERE
SopOrder_0.SopOrderID = SopOrderItem_0.SopOrderID
AND Company_0.CompanyID = SopOrder_0.CompanyID
AND SopOrderItem_0.SopProductID = SopProduct_0.SopProductID
AND SopOrder_0.SooOrderDate > '2018-01-01'
AND Company_0.CompanyID <> '66643115'
GROUP BY
Company_0.CoaCompanyName
,SopOrder_0.SooOrderDate
,Company_0.CompanyID
,Cell
,OrderType
,OrderMethod
FROM
SBS.PUB.SopOrderItem SopOrderItem_0
INNER JOIN SBS.PUB.Company Company_0 ON SopOrder_0.CompanyID = Company_0.CompanyID
INNER JOIN SBS.PUB.SopOrder SopOrder_0 ON SopOrderItem_0.SopOrderItemID = SopOrder_0.SopOrderID
LEFT JOIN SBS.PUB.SopProduct SopProduct_0 ON SopOrderItem_0.SopProductID = SopProduct_0.SopProductID
WHERE
SopOrder_0.CompanyID
,即使我知道它在表中,因为原始基本连接查询有效。
最佳答案
我想这就是你要找的:
SELECT ....
FROM SBS.PUB.Company Company_0
JOIN SBS.PUB.SopOrder SopOrder_0
ON Company_0.CompanyID = SopOrder_0.CompanyID
JOIN SBS.PUB.SopOrderItem SopOrderItem_0
ON SopOrder_0.SopOrderID = SopOrderItem_0.SopOrderID
JOIN SBS.PUB.SopProduct SopProduct_0
ON SopOrderItem_0.SopProductID = SopProduct_0.SopProductID
WHERE SopOrder_0.SooOrderDate > '2018-01-01'
AND Company_0.CompanyID <> '66643115'
关于sql - 编写联接的更好方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55145235/
我有一张维护要求表和相关的每月执行频率 维护 +----------+------+ | maint_id | freq | +----------+------+ | 1 | 6
我目前有这些表: CREATE TABLE #SECURITY_TEMP (ID CHAR(30)) CREATE TABLE #SECURITY_TEMP_PRICE_HISTORY (ID CHA
我有一张维护要求表和相关的每月执行频率 维护 +----------+------+ | maint_id | freq | +----------+------+ | 1 | 6
我有一个如下所示的表格 表tbl_veh VIN Record DateChange 11223344 123A 6/24/2012 11223344
我的应用程序的数据模型 群组有很多用户 用户所属组 用户有很多打卡 冲床属于用户 冲床属于PayPeriod PayPeriod hasMany Punch 找电话 $groups = $this->
使用 Join 或 GroupJoin,是否有任何方法可以为父表和子表中的字段生成聚合值。给定一个 Orders 表和一个 OrderDetails 表,使用下面的 2 个步骤我可以从 Orders
我有一个包含用户 ID 和用户名的用户表。另一个表有一个兴趣列表,包括兴趣和姓名。第三个表是一个连接表,包含 userid 和interestid。 对于每对用户,我想获取他们共同兴趣的数量。我尝试了
假设我有下表: 表A a_name | age | country Jordan | 5 | Germany Molly | 6 | Spain Paris | 7 | France John | 7
数据源是 CSV 文件的集合,因此没有实际的数据库。这是与日本已有数十年历史的遗留系统的集成。 我有一个 c# 函数需要将 2 个 DataTables 和 2 个列名作为参数。我的函数需要对这两个数
我有一种情况要在具有数据的elasticsearch中编写搜索查询,如下所示 {id:"p1",person:{name:"name",age:"12"},relatedTO:{id:"p2"}} {
我想创建具有父子关系的文档。 我有如下数据 parent_id = null的父文档数据 { "id": 1, "work
我有以下按预期工作的 SQL: SELECT p.ACCT_ID AS [Acct], a.ACCT_NAME AS [AcctName], p.PD_NO AS [Period],
我想使用 CriteriaBuilder 在连接 2 个表的位置进行查询。在 MySQL 中,我尝试进行的查询如下所示: SELECT * FROM order LEFT JOIN item ON o
使用带有collection标签的域Service,如下所示: @Entity public class Service extends AbstractEntity { private st
我有一个解决方案,通过连接同一个表两次,但我想知道以下查询是否可以优化? select oc.name as father_occupation, o.name as mother_occupatio
我知道除了知道什么是“最喜欢的编程卡通”之外,stackoverflow 会对我有所帮助:P 这是接受的答案: Bill Karwin 感谢大家的帮助(我想给你们加倍投票) 我的查询结果是这样的(这是
我有两个表格,可以在附图中看到。 表 A 包含部门、月份和平均。 表 B 包含月份、年份、RangeStart、RangeEnd 和 颜色。 如果您查看表 B 的屏幕截图,您将看到每个月都有绿色、黄色
我有一个 Linq to sql 如下: var members=db.Members.Include(x=> x.Contact).Count(); 现在由于一些错误的数据,我的成员中的所有联系人都
我有两个表(用户和帖子),我想写出一个用户的所有帖子(以及其他内容)。我想我应该使用 JOIN 和 WHERE,但我在使用 WHERE 时遇到错误。 这是我的代码: SELECT username,
在 Hibernate 是我的持久性提供者的项目中,我可以使用“join fetch”表达式发出查询,Hibernate 将生成反射(reflect)该内容的 SQL:包含使用有效比较路径的联接表达式
我是一名优秀的程序员,十分优秀!