有人可以看看我的查询。当我尝试取消对任何注释字段的注释时,oracle 会抛出错误。
SELECT *
FROM (
SELECT ratfac.rating_id,
ratfac.label_en,
ratfac.ratingmodel_factor_id,
ratfac.weight,
ratfac.rating_calculated,
ratfac.rating,
ratfac.rating_adjusted,
ratfac.override_comment,
ratfac.rating_override,
ratfac.notch_value,
ratfac.notch_value_calculated,
ratfac.notch_value_adjusted,
ratfac.score,
ratfac.score_calculated,
ratfac.score_adjusted,
ratfac.factor_comment
FROM vw_ratingfactor ratfac ) pivot ( min(ratingmodel_factor_id) ratingmodel_factor_id, min(weight) weight, min(rating_calculated) rating_calculated, min(rating) rating,
--MAX(RATING_ADJUSTED) as RATING_ADJ,
min(override_comment) override_comment, min(rating_override) rating_override, min(notch_value) notch_value,
--MIN(NOTCH_VALUE_CALCULATED) NOTCH_VALUE_CALCULATED,
--MIN(NOTCH_VALUE_ADJUSTED) NOTCH_VALUE_ADJUSTED,
min(score) score, min(score_calculated) score_calculated, min(score_adjusted) score_adjusted, min(factor_comment) factor_comment FOR label_en IN ('Market'
|| chr(38)
||'Competitiveness' AS marketcompetitiveness,
'Industry' AS industry,
'Company Strategy and Management' AS company_stratergy_mgmt,
'Financial Performance' AS financial_performance, …Run Code Online (Sandbox Code Playgroud) 我有两张桌子:
ranking_history
| user_id | ranking | time
| 1 | 2 | 2018-05-21
| 1 | 5 | 2018-04-28
| 2 | 9 | 2018-05-21
| 2 | 1 | 2018-04-28
Run Code Online (Sandbox Code Playgroud)
用户
| id | ranking
| 1 | 7
| 2 | 3
Run Code Online (Sandbox Code Playgroud)
我需要连接这两个表来生成一个如下所示的表:
| id | ranking | last_weeks_ranking | last_months_ranking
| 1 | 7 | 2 | 5
| 2 | 3 | 9 | 1
Run Code Online (Sandbox Code Playgroud)
这就是我尝试过的:
SELECT *, r1.ranking as last_weeks_ranking, r2.ranking as last_months_ranking
from …Run Code Online (Sandbox Code Playgroud) 我有一个与此类似的 PySpark DataFrame:
df = sc.parallelize([
("c1", "A", 3.4, 0.4, 3.5),
("c1", "B", 9.6, 0.0, 0.0),
("c1", "A", 2.8, 0.4, 0.3),
("c1", "B", 5.4, 0.2, 0.11),
("c2", "A", 0.0, 9.7, 0.3),
("c2", "B", 9.6, 8.6, 0.1),
("c2", "A", 7.3, 9.1, 7.0),
("c2", "B", 0.7, 6.4, 4.3)
]).toDF(["user_id", "type", "d1", 'd2', 'd3'])
df.show()
Run Code Online (Sandbox Code Playgroud)
这使:
+-------+----+---+---+----+
|user_id|type| d1| d2| d3|
+-------+----+---+---+----+
| c1| A|3.4|0.4| 3.5|
| c1| B|9.6|0.0| 0.0|
| c1| A|2.8|0.4| 0.3|
| c1| B|5.4|0.2|0.11|
| c2| A|0.0|9.7| 0.3|
| c2| …Run Code Online (Sandbox Code Playgroud) 我有这个查询
select
Id,
case when isThirdParty = 0 then sum(total) end as FirstPartyFees,
case when isThirdParty = 1 then sum(total) end as ThirdPartyFees
from
MyTable
group by
id, isThirdParty
Run Code Online (Sandbox Code Playgroud)
我得到了这个结果
Id FirstPartyFees ThirdPartyFees
------------------------------------ --------------------------------------- ---------------------------------------
DA29BDC0-BE3F-4193-BFDC-493B354CE368 15.00 0.00
2EF0B590-FE4F-42E8-8426-5864A739C16B 5.00 0.00
246DC3D8-732F-4AE3-99F3-BDEBF98F7719 15.00 0.00
FC81F220-ED54-48FE-AE1B-C394492E82A4 5.00 0.00
336D9CF1-6970-48BA-90E5-C7889914DDCB 114.00 0.00
6F2EEF6F-5FA1-42E5-A988-DB88037DAB92 5.00 0.00
80763B37-68E1-4716-B32A-FE82C1700B52 15.00 0.00
DA29BDC0-BE3F-4193-BFDC-493B354CE368 0.00 1.00
2EF0B590-FE4F-42E8-8426-5864A739C16B 0.00 1.00
246DC3D8-732F-4AE3-99F3-BDEBF98F7719 0.00 1.00
FC81F220-ED54-48FE-AE1B-C394492E82A4 0.00 1.00
336D9CF1-6970-48BA-90E5-C7889914DDCB 0.00 0.00
6F2EEF6F-5FA1-42E5-A988-DB88037DAB92 0.00 1.00
80763B37-68E1-4716-B32A-FE82C1700B52 0.00 1.00
Run Code Online (Sandbox Code Playgroud)
如您所见,我得到了第一方和第三方的重复项。如何将同一 ID …
我目前有以下 SQL 语句:
SELECT
[Manager].[Name],
COUNT([Project].[ProjectId]) AS TotalProjects
FROM
([Project]
INNER JOIN
[Manager] ON [Project].[ManagerId] = [Manager].[ManagerId])
WHERE
[Project].[CurrentStatusId] = 5
GROUP BY
[Manager].[Name]
Run Code Online (Sandbox Code Playgroud)
它目前列出了每个经理的总项目数。我想让它按照完成的年份来划分项目。因此,基本上计算每个经理每年(2016 年、2017 年等)的项目总数,以及所有时间的项目总数。我可以使用[Project].[CurrentStatusDt]日期列。
我想在一个查询中同时做这两个 COUNT,这是最好的方法?我想根据 status_id 计算销售和销售线索
SELECT COUNT(status_id) as Leads FROM activities WHERE YEARWEEK(`date`, 1) = YEARWEEK(CURDATE(), 1) AND status_id =5
SELECT COUNT(status_id) as Sales FROM activities WHERE YEARWEEK(`date`, 1) = YEARWEEK(CURDATE(), 1) AND status_id =4
Run Code Online (Sandbox Code Playgroud) 我有一张包含基本员工详细信息的表格,如下所示:
表:tblEmployees
EmpID Name Contact Sex
100 John 55555 M
200 Kate 44444 F
300 Sam 88888 M
Run Code Online (Sandbox Code Playgroud)
我想获得如下特定员工的查询结果,其中 EmpID = 200
Col1 Col2
EmpID 200
Name Kate
Sex F
Run Code Online (Sandbox Code Playgroud) 样品:
print (df)
Week Category Sales
0 202001 Red 100
1 202001 White 200
2 202002 Red 300
3 202002 White 700
4 201901 Red 800
5 201901 White 900
6 201902 Red 100
7 201902 White 200
Run Code Online (Sandbox Code Playgroud)
样品:
输出:
Week Category 2019 2020
0 1 Red 800 100
1 1 White 900 900
2 2 Red 100 300
3 2 White 200 700
Run Code Online (Sandbox Code Playgroud) 考虑以下:
tribble(
~"1", ~"2", ~"3", ~"4",
"bob", "sally", "fred","jim",
"2011", "2012", "2013", "2014"
)
Run Code Online (Sandbox Code Playgroud)
在上面,列“1”存储我们真正想要分隔列的值,例如:
tribble(
~col, ~name, ~year,
"1", "bob", "2011",
"2", "sally", "2012",
"3", "fred", "2013",
"4", "jim", "2014"
)
Run Code Online (Sandbox Code Playgroud)
起初,我尝试过,pivot_longer(everything())但这会产生重复的行。
name value
<chr> <chr>
1 1 bob
2 2 sally
3 3 fred
4 4 jim
5 1 2011
6 2 2012
7 3 2013
8 4 2014
Run Code Online (Sandbox Code Playgroud)
我考虑过尝试pivot_wider,但我无法部分选择上面值列中的年份或名称。
有任何想法吗?这当然是一个玩具示例 - 基本思想是采用多行并将它们转换为列而无需重复代码。
现在第二列的 PN 可以不时重复。
虽然我设法计算了完整和不完整,但似乎无法弄清楚如何说 PN 和 EntryDate 组合(串联)是唯一的,并希望以此为基础进行计数(将绿色和黄色行视为相同的 PN)。
基本上,如果“已完成”行的数据是完整的,而 null 是不完整的。
数据库是 MS SQL
感谢
所有帮助,
谢谢