小编Jin*_*ong的帖子

无法在 presto 中将 '' 转换为 bigint

我试图在我的查询中清除 'null',但是运行它时仍然出错,一直告诉我 'cannot cast'' to bigint,有什么办法可以解决它?

我的查询

select m.app, m.hour,m.user_id, 
 m.avg_minutes_watched, n.userid, n.watched_mins, n.active FROM 

(SELECT app,
substr(hour,1,8) hour, 
CAST(COALESCE(json_extract_scalar(json, '$.user_id'), '-999999') as BigInt) user_id,
CAST(COALESCE(json_extract_scalar(json, '$.playback_time'), '-999999') as BigInt) /60000 avg_minutes_watched
FROM prod
WHERE event_type = 'user_session_complete' AND hour > '20180331' and hour < '20180501')m

left join

(select userid, watched/60000 watched_mins,
(case when watched/60000 >= 2 then 'active' else 'not_active' end) active  from est where realdate > '2018-03-31' and realdate < '2018-05-01') n

on m.user_id = n.userid
order by …
Run Code Online (Sandbox Code Playgroud)

sql casting type-conversion presto trino

6
推荐指数
1
解决办法
9462
查看次数

在for循环中使用if ... else返回字符串

所以在这里我试图将字符串' ABcsad f!,'转换为
string 'abcsadf',所以基本上我正在尝试将空格和非alpha替换为'',但是我的代码根本不起作用...

s = ' ABcsad f!,'

def norm(s):
    b=''
    i=0
    for i in range(0,len(s)+1):
        if (s[i].isalpha() is False) or (s[i].isspace() is False) :
            return b+=''
        else:
            return b+=s[i]
        i = i+1   

print(norm(s))
Run Code Online (Sandbox Code Playgroud)

谁能告诉我我哪里出了问题?

python for-loop python-3.x

1
推荐指数
1
解决办法
123
查看次数

如何使用python从数据结构中提取字典?

因此,这是一个名为grade_lists的表,该表将学生的姓名映射到他们的考试成绩列表。等级应从字符串转换为整数。例如,grade_lists ['Thorny'] == [100,90,80]。有人能帮我吗?

 grades = [ #here is the table
    ['Student', 'Exam 1', 'Exam 2', 'Exam 3'],
    ['Thorny', '100', '90', '80'],
    ['Mac', '88', '99', '111'],
    ['Farva', '45', '56', '67'],
    ['Rabbit', '59', '61', '67'],
    ['Ursula', '73', '79', '83'],
    ['Foster', '89', '97', '101']
]
Run Code Online (Sandbox Code Playgroud)

python python-3.x

0
推荐指数
1
解决办法
59
查看次数

标签 统计

python ×2

python-3.x ×2

casting ×1

for-loop ×1

presto ×1

sql ×1

trino ×1

type-conversion ×1