-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
groupBy datetime #10
Comments
Ignore the comment on the other side, I didn't see the ticket here. |
You can do this already, it's just not that straightforward. var query = require("sql-query");
var sql = (new query.Query()).select();
sql.from("myTable")
.count('id', 'sum')
.fun('strftime', [ '%Y-%m-%d', 'date' ], 'year_month_date')
.groupBy('year_month_date');
console.log(sql.build());
// SELECT COUNT(`id`) AS `sum`, STRFTIME(`%Y-%m-%d`, `date`) AS `year_month_date` FROM `myTable` GROUP BY `year_month_date` |
Wait, there's a problem in that query... the string format is escaped as an identifier, I'm going to try and fix this. |
Every string passed to functions is supposed to be an identifier. What do you think about creating a special object? Example: var query = require("sql-query");
var sql = (new query.Query()).select();
sql.from("myTable")
.count('id', 'sum')
.fun('strftime', [ query.Text('%Y-%m-%d'), 'date' ], 'year_month_date')
.groupBy('year_month_date');
console.log(sql.build());
// SELECT COUNT(`id`) AS `sum`, STRFTIME('%Y-%m-%d', `date`) AS `year_month_date` FROM `myTable` GROUP BY `year_month_date` |
I think this could be a good way, but I leave that to you as I want to use this functionallity in node-orm2 (see referenced ticket above). |
Feature request: I want to count items grouped by a DATETIME field. To group on the day I am doing this in sqlite3:
The text was updated successfully, but these errors were encountered: