小编fin*_*col的帖子

按小时对时间戳进行分组 SQLite

我正在尝试按小时对数据类型为 TimeStamp 的时间戳列进行分组。

所以这适用于按天分组:

SELECT * FROM INFO
GROUP BY
DATE(timestamp)
Run Code Online (Sandbox Code Playgroud)

我尝试了以下按小时分组的方法:

SELECT * FROM INFO
GROUP BY
HOUR(timestamp)
Run Code Online (Sandbox Code Playgroud)

但这给了我错误:没有这样的功能:HOUR:

我见过类似的问题,但使用的是 DateTime,而不是 TimeStamp。

另外我想知道如何按任何时间段进行分组,例如按 24 小时、按 48 小时、按周等。

sql sqlite group-by

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

检查字符串是否包含确切的关键字

我有一个字符串列表。对于每个字符串,我希望查看单词“joe”的第一次出现是否存在。例如,我用空格分隔,因为我不想计算“joey”这个词。

我当前的代码计算单词“joe”的每次出现,如何编辑它以便它只计算该单词的第一次出现,然后移至列表中的下一个字符串。

public int counter(List<String> comments) {
    int count = 0;
    String word = "joe";
    for (String comment : comments) {
        String a[] = comment.split(" ");

        for (int j = 0; j < a.length; j++) {

            if (word.equals(a[j])) {
                count++;

            }
        }
        System.out.println(comment);
    }
    System.out.println("count is " + count);
    return count;
}
Run Code Online (Sandbox Code Playgroud)

编辑

str.add("the hello my the name is joe the this joe is a test");
str.add("i was walking down joe then suddenly joe said hi");
Run Code Online (Sandbox Code Playgroud)

我希望我的代码为此返回 2 (joe 已出现在每个字符串中)

java arrays arraylist

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

arraylist ×1

arrays ×1

group-by ×1

java ×1

sql ×1

sqlite ×1