我在mySQL中有一个表(t1),它生成下表:
type time full
0 11 yes
1 22 yes
0 11 no
3 13 no
我想从中创建第二个表(t2),它将总结t1中的信息,如下所示:
type time num_full total
0 11 1 2
1 22 1 1
3 13 0 1
我希望能够遍历类型列,以便能够启动此摘要,类似于for循环。类型最多可以为n,因此我宁愿不编写n + 1 WHERE
语句,每次添加更多类型时都必须更新代码。
注意t2如何跳过值2的类型?当我尝试循环时,这也逃避了我。我只希望找到的类型在t2中创建行。
虽然直接回答会很好,但是如果能够指出一些可以解决这个问题的来源,或者两者兼而有之,会更有帮助。
答案 0 :(得分:0)
这可能会做你想要的事情
if (roundedMax-roundedMin)/idealTick <= 2
idealTick *= 5
else if (roundedMax-roundedMin)/idealTick <= 5
idealTick *= 2
取决于您希望如何汇总时间列。
这是按功能分组的参考起点:https://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html
这里用于创建语法
https://dev.mysql.com/doc/refman/5.6/en/create-table.html