我有一个看起来像这样的数据集:
+------------------------|-----+
| timestamp| zone|
+------------------------+-----+
| 2019-01-01 00:05:00 | A|
| 2019-01-01 00:05:00 | A|
| 2019-01-01 00:05:00 | B|
| 2019-01-01 01:05:00 | C|
| 2019-01-01 02:05:00 | B|
| 2019-01-01 02:05:00 | B|
+------------------------+-----+
Run Code Online (Sandbox Code Playgroud)
对于每个小时,我需要计算哪个区域的行数最多,最后得到一个如下所示的表:
+-----|-----+-----+
| hour| zone| max |
+-----+-----+-----+
| 0| A| 2|
| 1| C| 1|
| 2| B| 2|
+-----+-----+-----+
Run Code Online (Sandbox Code Playgroud)
我的说明说我需要使用 Window 函数和“group by”来找到我的最大计数。
我已经尝试了一些东西,但我不确定我是否接近。任何帮助,将不胜感激。
我想知道是否有任何方法可以避免 Scala REPL 通过设置环境变量或其他方式来截断输出?
例子
scala> typeOf[Iterator[_]].members.mkString("\n")
res6: String =
override def toString(): String
def toStream: scala.collection.immutable.Stream[A]
def toIterator: Iterator[A]
def toTraversable: Traversable[A]
def sameElements: <?>
def copyToArray[B >: A](xs: Array[B],start: Int,len: Int): Unit
def patch: <?>
def duplicate: <?>
def length: <?>
def sliding$default$2: <?>
def sliding: <?>
def grouped: <?>
class GroupedIterator extends
def buffered: <?>
def indexOf: <?>
def indexOf: <?>
def indexWhere: <?>
def indexWhere: <?>
def find(p: A => Boolean): Option[A]
def contains: <?>
def …Run Code Online (Sandbox Code Playgroud) 我需要用大数字做一些精确计算,我一直在尝试使用 Scala,BigDecimal但我注意到精度损失。
举个例子:
2^63 == 9223372036854775808
2^64 == 18446744073709551616
Run Code Online (Sandbox Code Playgroud)
但是当我做
println(BigDecimal.decimal(scala.math.pow(2, 63)).toBigIntExact())
println(BigDecimal.decimal(scala.math.pow(2, 64)).toBigIntExact())
Run Code Online (Sandbox Code Playgroud)
我得到
9223372036854776000 != 9223372036854775808
18446744073709552000 != 18446744073709551616
Run Code Online (Sandbox Code Playgroud)
我不知道如果我能得到确切的BigInt。
也许我必须采取其他方法。
有人可以帮我解决这个问题吗?
我有以下数据集作为 MySql 引擎版本 5.x 中的示例
+-----------+------------+
| name | occupation |
+-----------+------------+
| Samantha | Doctor |
| Julia | Actor |
| Maria | Actor |
| Meera | Singer |
| Ashely | Professor |
| Ketty | Professor |
| Christeen | Professor |
| Jane | Actor |
| Jenny | Doctor |
| Priya | Singer |
+-----------+------------+
Run Code Online (Sandbox Code Playgroud)
我想旋转表中的职业列,以便每个名称按字母顺序排序并显示在其相应的职业下方。输出列标题应分别为 Doctor、Professor、Singer 和 Actor。
我试试这个
SELECT CASE occupation WHEN 'Doctor' THEN name END AS Doctor,
CASE occupation …Run Code Online (Sandbox Code Playgroud) scala ×3
apache-spark ×1
bigdecimal ×1
bigint ×1
math ×1
mysql ×1
pivot ×1
pivot-table ×1
precision ×1
scala-repl ×1
sql ×1
truncate ×1