for lan in songs_language: sql = ''' select count(list_tags),sum(song_count),sum(play_count),sum(star_count),sum(share_count),sum(comment_count) from (select list_tags,star_count,share_count,comment_count,song_count,play_count from playlist_info where list_tags like '%{lan}%');'''.format(lan=lan) table = spark.sql(sql) for row in table: count_list.append(row[0]) count_song.append(row[1]) count_play.append(row[2]) count_star.append(row[3]) count_share.append(row[4]) count_comment.append(row[5]) 如何打印出列表中的值,而不是对象
时间: 2024-04-13 10:28:26 浏览: 23
要打印出列表中的值而不是对象,你可以使用循环遍历列表,并使用`print`函数打印每个元素的值。在你的代码中,你可以像这样修改循环部分:
```python
for row in table:
count_list.append(row[0])
count_song.append(row[1])
count_play.append(row[2])
count_star.append(row[3])
count_share.append(row[4])
count_comment.append(row[5])
# 打印列表中的值
print("count_list:", count_list)
print("count_song:", count_song)
print("count_play:", count_play)
print("count_star:", count_star)
print("count_share:", count_share)
print("count_comment:", count_comment)
```
这样,列表`count_list`、`count_song`、`count_play`、`count_star`、`count_share`和`count_comment`中的值将被打印出来。确保在需要打印值的位置使用适当的缩进,并在变量名后添加冒号和空格。
相关问题
air_station_addr=${lan0hwaddr//:/} 上述代码什么意思
这段代码是在Linux shell中使用的,它的含义是将变量`lan0hwaddr`中的冒号(`:`)替换为空格,并将结果赋值给变量`air_station_addr`。具体来说,`${lan0hwaddr//:/}`中的`//`表示全局匹配,将所有的`:`都替换为空格。`$lan0hwaddr`表示获取变量`lan0hwaddr`的值。因此,这段代码的作用是去掉变量`lan0hwaddr`中的冒号。
转换为hive, STR_SQL:=' INSERT INTO jyfx_PRODUCT_ACCEPT_2022 SELECT A.obj_id,null,A.apply_obj_spec,null,A.create_date,A.region_id, A.create_ORG_ID,sysdAte,null,A.cust_order_id, A.ORDER_item_id,null,null,null, A.BELONG_lan_id,create_staff FROM ord_so.order_item@to_CRM_TEST A WHERE A.order_item_cd = ''1300'' and A.status_cd in (''301200'',''201300'') AND to_char(A.create_date,''yyyymmdd'') >= to_char(sysdate-35,''yyyymmdd'') AND A.SERVICE_OFFER_ID=4010100000 '; EXECUTE IMMEDIATE STR_SQL; --执行了一个名为STR_SQL的动态SQL语句。 COMMIT; --提交了之前的事务 INSERT INTO JOB_TIME_REC VALUES('jyfx_HOUR',V_START_TIME,SYSDATE, (SYSDATE-V_START_TIME)*24*3600,'受理'); --将一条记录插入到JOB_TIME_REC表中,包括了'jyfx_HOUR'、V_START_TIME、SYSDATE、(SYSDATE-V_START_TIME)243600和'受理'这些值。 COMMIT; --提交这次插入操作的事务 V_START_TIME:=SYSDATE;--将V_START_TIME的值更新为当前的系统时间
以下是将给定的脚本转换为Hive SQL的结果:
```sql
INSERT INTO jyfx_PRODUCT_ACCEPT_2022
SELECT A.obj_id, NULL, A.apply_obj_spec, NULL, A.create_date, A.region_id, A.create_ORG_ID, current_date, NULL, A.cust_order_id, A.ORDER_item_id, NULL, NULL, NULL, A.BELONG_lan_id, create_staff
FROM ord_so.order_item A
WHERE A.order_item_cd = '1300' and A.status_cd IN ('301200', '201300')
AND from_unixtime(unix_timestamp(A.create_date, 'yyyyMMdd'), 'yyyyMMdd') >= from_unixtime(unix_timestamp(current_date - INTERVAL 35 DAY), 'yyyyMMdd')
AND A.SERVICE_OFFER_ID = 4010100000;
INSERT INTO JOB_TIME_REC VALUES ('jyfx_HOUR', '2023-07-12 00:00:00', current_timestamp(), unix_timestamp(current_timestamp()) - unix_timestamp('2023-07-12 00:00:00'), '受理');
V_START_TIME := current_timestamp();
COMMIT;
```
请注意,Hive不支持动态SQL语句的执行(EXECUTE IMMEDIATE),因此您需要手动将其分解为适当的Hive语句。此外,Hive中没有类似PL/SQL的变量赋值语句(V_START_TIME := SYSDATE),因此您需要根据实际需要进行调整。最后,Hive不支持直接使用TO_CHAR函数,而是使用from_unixtime和unix_timestamp函数来进行日期格式转换。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)