Postgresql数过去数周(Postgresql count by past weeks)
select id, wk0_count from teams left join (select team_id, count(team_id) as wk0_count from ( select created_at, team_id, trunc(EXTRACT(EPOCH FROM age(CURRENT_TIMESTAMP,created_at)) / 604800) as wk_offset from loan_files where loan_type <> 2 order by created_at DESC) as t1 where wk_offset = 0 group by team_id) as t_wk0 on teams.id = t_wk0.team_id
我创建了上面的查询,显示了每个团队在给定的一周内完成的贷款数量。 第0周是过去七天。
理想情况下,我需要一张表格,显示每个团队在过去8周内所做的贷款数量,按周分组。 输出结果如下所示:
任何想法最好的方式来做到这一点?
select id, wk0_count from teams left join (select team_id, count(team_id) as wk0_count from ( select created_at, team_id, trunc(EXTRACT(EPOCH FROM age(CURRENT_TIMESTAMP,created_at)) / 604800) as wk_offset from loan_files where loan_type <> 2 order by created_at DESC) as t1 where wk_offset = 0 group by team_id) as t_wk0 on teams.id = t_wk0.team_id
I've created the query above that shows me how many loans each team did in a given week. Week 0 is the past seven days.
Ideally I want a table that shows how many loans each team did in the last 8 weeks, grouped by week. The output would look like:
Any ideas on the best way to do this?
原文:https://stackoverflow.com/questions/42300829
最满意答案
我试图在我的电脑上解决您的问题。
我所做的更改是我迭代当前行,并通过char 将它插入数组 char。
这段代码工作得很好:
#include <string> #include <iostream> #include <fstream> int main(){ std::ifstream inputMap("C:\\Res\\Level1.txt"); char arr[6][6]; for (int i = 0; i < 6; i++) { std::string input; std::getline(inputMap, input); for (int k = 0; k < input.length(); k++) { arr[i][k] = input[k]; std::cout << input[k]; } std::cout << std::endl; } std::cout << std::endl; for (size_t l = 0; l < 6; l++) { for (size_t m = 0; m < 6; m++) { std::cout << arr[l][m]; } std::cout << std::endl; } system("PAUSE"); return 0; }
输出是所需的(我在这里复制)。
为了您的目的 ,请不要在第一次或第二次打印;)
++++++ +H + + + + + + X+ ++++++ ++++++ +H + + + + + + X+ ++++++
I tried to solve your problem on my computer.
The change I made is that I iterate the current line and insert it to the array char by char.
this code works very well:
#include <string> #include <iostream> #include <fstream> int main(){ std::ifstream inputMap("C:\\Res\\Level1.txt"); char arr[6][6]; for (int i = 0; i < 6; i++) { std::string input; std::getline(inputMap, input); for (int k = 0; k < input.length(); k++) { arr[i][k] = input[k]; std::cout << input[k]; } std::cout << std::endl; } std::cout << std::endl; for (size_t l = 0; l < 6; l++) { for (size_t m = 0; m < 6; m++) { std::cout << arr[l][m]; } std::cout << std::endl; } system("PAUSE"); return 0; }
The output is as desired (I copied it here).
For your purpose, just don't print it in the first or second time ;)
++++++ +H + + + + + + X+ ++++++ ++++++ +H + + + + + + X+ ++++++
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
你应该使用vector
>来存储数据,因为你事先并不知道要读取多少数据。 #include #include #include #include using namespace std; int main() { const string FileName = "a.txt"; ifstream fin ( FileName ); if ( fin.fail() ) ... -
由于您使用的是C ++,因此您需要使用string和vector 。 #include
#include #include #include using namespace std; int main() { ifstream file("file"); string line; vector names; if (file.is_open()) while (g ... -
尝试将文本文件(ifstream)转换为c ++中的二维字符数组(Trying to convert a text file (ifstream) into a 2D array of chars in c++)[2022-10-23]
我试图在我的电脑上解决您的问题。 我所做的更改是我迭代当前行,并通过char 将它插入数组 char。 这段代码工作得很好: #include#include #include int main(){ std::ifstream inputMap("C:\\Res\\Level1.txt"); char arr[6][6]; for (int i = 0; i < 6; i++) { std: ... -
也许是这样的 for (int r = 0; r < rows; r++) { int c = 0; // keep reading until we hit a space char ch = inFile.get(); while (ch != ' ') { array[r][c] = ch; c++; ch = inFile.get(); } // now read the score in ...
-
选择文本文件中的特定数据,以c ++格式导入二维数组(Select specific data in text file to import in 2d array in c++)[2023-09-07]
这应该让你去: #include#include #include #include struct XY { int x; int y; }; using std::ifstream; using std::vector; using std::cerr; using std::endl; using std::string; int main() { vector data; ifstre ... -
您可以使用stringstream从每行中提取数字。 此外,您不需要有一个string数组。 你可以只使用一个string 。 int main() { ifstream file("text.txt"); if(file.is_open()) { for(int i = 0; i < 1000; ++i) { string row; if ( std::getline(file, row) ) ...
-
在C ++中使用std :: ifstream读取ASCII文本文件(Reading ASCII text file using an std::ifstream in C++)[2024-05-21]
我有一个阿拉伯文件(ASCII),其中包含:121101الزبونكمال121102الزبونسعيد121103الزبونعمار 经过一番澄清后,OP希望: 编写读取uft8和ANSI文件的通用函数 为了能够以相同的方式处理内容,我建议转换为UTF-16编码的std::wstring 。 OP似乎是针对Windows平台开发的,其中UTF-16是大多数API所期望的编码。 在其他平台(Linux)上,将所有内容转换为UTF-8可能更合适。 将ANSI文本文件读入UTF-16编码的wstring ... -
如何只读取ifstream中的字符并忽略c ++中的数字?(How to read only chars from ifstream and ignore numbers in c++?)[2023-01-10]
char c; while( file >> c ) { if( !isdigit( c ) ) { // if( ( c >= 'A' && C <= 'Z' ) || ( c >= 'a' && c <= 'z' ) ) { // do stuff with c } } 或者稍微更惯用,使用isalpha 。 这可能取决于您的C ++环境的语言环境设置。 理想情况下,您应该使用一个好的Unicode库,除非您可以保证输入文件。 char c; while( f ...