gpt4 book ai didi

google-bigquery - 如何在 BigQuery(或迷你图或颜色渐变)中构建 "Star Rating"报告

转载 作者:行者123 更新时间:2023-12-04 13:06:45 24 4
gpt4 key购买 nike

假设我有以下示例输入:

WITH Ratings AS (
(SELECT 'A' name, 2 score) UNION ALL
(SELECT 'B' name, 0 score) UNION ALL
(SELECT 'C' name, 5 score) UNION ALL
(SELECT 'D' name, 1 score))
哪里 score是 0 到 5 之间的数字。
如何生成显示名称和相应星数的报告?

最佳答案

我们可以使用两个 Unicode 字符将星级构建为字符串:

★ - Unicode code point 9733 
☆ - Unicode code point 9734

我们可以使用 CODE_POINTS_TO_STRING 构建星星的功能,以及 REPEAT 函数以产生正确数量的星星

结合在一起,样本输入的解决方案将是:
WITH Ratings AS (
(SELECT 'A' name, 2 score) UNION ALL
(SELECT 'B' name, 0 score) UNION ALL
(SELECT 'C' name, 5 score) UNION ALL
(SELECT 'D' name, 1 score))

SELECT
name,
CONCAT(
REPEAT(CODE_POINTS_TO_STRING([9733]), score),
REPEAT(CODE_POINTS_TO_STRING([9734]), 5-score)) score
FROM Ratings

它将产生以下结果:
name    score
A ★★☆☆☆
B ☆☆☆☆☆
C ★★★★★
D ★☆☆☆☆

关于google-bigquery - 如何在 BigQuery(或迷你图或颜色渐变)中构建 "Star Rating"报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48951840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com