在sql中使用WITH
时遇到以下问题。
WITH ctes AS (
SELECT *, ROW_NUMBER() OVER (PARTITION BY a.UserID, a.Type, a.CreateDate
ORDER BY COALESCE(CASE WHEN a.Type = 0 THEN a.CreateDate END AS CheckIn,
CASE WHEN a.Type = 1 THEN a.CreateDate END AS CheckOut)) rn
)
我无法将as
关键字放在case语句中。有人可以帮帮我吗 ?这说明语法不正确。
答案 0 :(得分:0)
您不能为函数的参数赋予别名。
删除别名:
import cats.data.Reader
trait Service{
def f1: Reader[Map[String, Int], Int] = Reader(_("name"))
def f2: Reader[Map[String, Int], Int] = Reader(_("age"))
}
trait Service2 {
type Env = (Service, Map[String,Int])
def f(i: Int): Reader[Env, Int] =
for {
s <- Reader((_: Env)._1) //extract input type Service
r1 <- s.f1.local((_: Env)._2)
r2 <- s.f2.local((_: Env)._2)
} yield r1 + r2 + i
}
我注意到,两个案例表达式都返回WITH ctes AS (
SELECT *, ROW_NUMBER() OVER (PARTITION BY a.UserID, a.Type, a.CreateDate
ORDER BY COALESCE(CASE WHEN a.Type = 0 THEN a.CreateDate END,
CASE WHEN a.Type = 1 THEN a.CreateDate END))
)
。如果这不是拼写错误,则可以删除调用以合并并仅对大小写进行一次调用,将顺序缩短为:
a.CreateDate