SQL函数错误创建函数语句

时间:2018-03-30 09:49:17

标签: sql hive

我想编写一个返回浮点值的sql函数。 我的代码是:

CREATE FUNCTION def_profile(float,float,int,int) RETURNS FLOAT AS (
    BEGIN
      sum_profile = 0
      CASE $3 BETWEEN 0 AND $2 / 4. THEN sum_profile = sum_profile + 1
           $3 BETWEEN $2 / 4. AND $2 / 4. THEN sum_profile = sum_profile + 2
           $3 BETWEEN $2 / 4. AND $2 / 4. THEN sum_profile = sum_profile + 2
           $3 BETWEEN $2 / 4. AND $2 THEN sum_profile = sum_profile + 3.5

      CASE $4 BETWEEN 0 AND $2 / 4. THEN sum_profile = sum_profile + 2.5
           $4 BETWEEN $2 / 4. AND $2 / 4.THEN sum_profile = sum_profile + 4.
           $4 BETWEEN $2 / 4. AND $2 / 4. THEN sum_profile = sum_profile + 2.5
           $4 BETWEEN $2 / 4. AND $2 THEN sum_profile = sum_profile + 3
      RETURN sum_profile
    END )

我用以下方式调用我的函数:

SELECT
    uuid,
    sum_profile(MAX(nb_page_views),MAX(nb_sessions),nb_page_views,nb_sessions), ...

但是我有一条错误消息mismatched input '(' expecting AS near 'def_profile' in create function statement

我没有发现问题所在。

感谢您的帮助

0 个答案:

没有答案