[英]MS SQL Operand type clash: date is incompatible with bigint
I'm trying to solve a question on HackerRank using the Tabibitosan method that I read about. 我正在尝试使用我读过的Tabibitosan方法解决有关HackerRank的问题。 Here is a link to the question if you want to read it: https://www.hackerrank.com/challenges/projects/problem
如果您想阅读该问题,请访问以下链接: https : //www.hackerrank.com/challenges/projects/problem
Here is my error: Line 1 Operand type clash: date is incompatible with bigint 这是我的错误:第1行操作数类型冲突:日期与bigint不兼容
Here is my code: 这是我的代码:
SELECT MIN(start_date), MAX(end_date)
FROM (
SELECT
start_date, end_date,
dense_rank() OVER (ORDER BY start_date) AS rn,
start_date - dense_rank() OVER (ORDER BY start_date) AS grouping
FROM projects
) AS r
GROUP BY grouping
ORDER BY COUNT(*) ASC, MIN(start_date) ASC;
There may be other issues with my code but you don't need to fix those since I'm still learning and figuring things out but I can't solve this error and searching has not helped. 我的代码可能还有其他问题,但是您不需要修复这些问题,因为我仍在学习和解决问题,但是我无法解决此错误,搜索也无济于事。
Table: 表:
Task_ID, Int
Start_date, date
End_date, date
Date format: 2015-10-31 日期格式:2015-10-31
I'm not sure why the code isn't working since the goal is basically the same as the date section of where I found the Tabibitosan Method: https://community.oracle.com/docs/DOC-915680 我不确定代码为什么不起作用,因为目标基本上与我发现Tabibitosan方法的日期部分相同: https ://community.oracle.com/docs/DOC-915680
The problem is start_date - dense_rank() OVER (ORDER BY start_date)
. 问题是
start_date - dense_rank() OVER (ORDER BY start_date)
。 The error is telling you the problem here; 错误在这里告诉您问题所在; but you can't subtract a
bigint
value from a date
. 但是您不能从
date
减去bigint
值。 You need to use DATEADD
. 您需要使用
DATEADD
。 So replace the expression above with: 因此,将上面的表达式替换为:
DATEADD(DAY,-(dense_rank() OVER (ORDER BY start_date)),start_date)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.