Skip to content

Is there a way to group by part of a datetime column in SQL?

I have a dataframe something like this. is there a way to return a table that sums the dollar values based on the time down to the minute. For example: Notice that the “time” data in the original data set spans over a few days but I am only concerned with the time of day. Thanks Answer I’m n…

Convert Postgres IPv6 column TEXT field into JSON

Trying to convert a text field to a JSON field in Postgres. The field was an IPv6 address those having multiple semicolons e.g.: “14:eth1:vTA1:::4:” Trying to run smth like: Results in: Failed to convert text field to JSON. Details: invalid input syntax for type json DETAIL: Expected end of input,…

MySQL – Slow query

Sorry for the long post, but the tables involved are quite big. When I run the query bellow it normally takes about 1m to run. However, when I remove the correlated sub-query I get the query down to 15 seconds. So I think that’s the actual problem. Problem is, I don’t really know how to get the SU…

Query with group by date

I’m working on the following user table, where role = 2 means the user is an instructor, and role = 3 means that the user is a student. My goal is to select the sum value of all instructors and students, grouped by date. The result should look like this: In this case, on 2020-07-01, I had 1 instructor a…

How to optimize a SQL query that combines INNER JOINs and DISTINCT?

The query above returns me 5222 rows, and it runs locally in 0.63 seconds. I’m wondering if it is as fast as it can be or if I can tweak it further somehow, as this dataset will grow fast overtime. Things that I’ve tried without change in speed: 1 – Change the join order, joining from the sm…