在 SQL(databricks/spark SQL)中进行透视时,有没有办法动态设置 for-in 的“in”部分?
例如,这段代码:
select *
from (select office, country, revenue from sales)
pivot (
sum(revenue)
for country in ('US', 'CA', 'UK')
)
Run Code Online (Sandbox Code Playgroud)
...工作正常,但该country列每个月都会有不同的值,所以我不想每次都查找并重新编写代码。我尝试将country和 select distinct country from sales放在那里,但这些不起作用。有任何想法吗?
我正在尝试建立使用局部变量的技能.为了使变量成为局部变量,我在我想要使用它的函数中声明它,对吧?
但如果我经常使用这个功能,我不会一遍又一遍地声明这个变量吗?这样可以吗?
例如,如果我有这样的函数:
function myFunction() {
var myVariable;
// some code that requires myVariable
}
Run Code Online (Sandbox Code Playgroud)
......我每次都会宣布myVariable.每次调用函数时,这是否会为myVariable留出内存空间?有没有解决的办法?
我有一个包含字符串的数组,我想将这些项目作为单个字符串返回,但它们之间有空格.
listProperties() {
this.properties = "";
this.state.withoutSuit.forEach(function (i, j) {
this.properties += i;
this.properties += " ";
});
console.log(this.properties);
return this.properties;
}
Run Code Online (Sandbox Code Playgroud)
所以在构造函数中我将this.state.withoutSuit作为我的数组,并将this.properties作为我将存储其间隔开的字符串版本的地方.
在函数中,我首先将this.properties设置为空字符串,然后我想用withoutSuit数组项填充它.
但是当我进入forEach循环时,this.properties是未定义的.我认为这是因为"this"现在指的不是构造函数,而是指this.state.withoutSuit: - 是吗?
如果是这样,我如何从循环中引用属性变量?
谢谢!