Skip to content

Tag: mysql

SQL selecting most recent row inside join

I have 2 tables companies and invoices I want to select all companies with their most recent invoice price. I don’t seem to get it working. This is what I tried: But the query loads very long and I don’t know why. The structure looks like this: companies invoices The BC_ID is the same as the compa…

SELECT with a variable

I have 3 tables : t_object : With all the classes t_operation : With all the operations, link with t_object.Object_ID = t_operation.Object_ID t_operationtag : With all the tag value for each operation, link with t_operation.OperationID = t_operationtag.ElementID I try to get an list for each of my operation (…

calculating percentage on multiple sql tables

There are 2 tables mobile and web Table name: Mobile Table name: web I need to calculate percentage of users who only visited : mobile, web and both. That is, the percentage of users who are only in the mobile table, only in the web table and in both tables. The sum should be 1. I tried using union but

Why I get error group by result of subquery?

I want to find the number of trace records which has same telephone,project_id,create_time,trace_content But this sql: returns wrong result. If I use: returns correct result. Mysql version is 5.6.26 Could anyone tell me the reason? For example the table contains these data: id = 1, project_id = 1, telephone =…

Selecting all entries in a table before this month

I’ve been trying different solutions but none seem to return the same values as I get from excel. I want to return all the items from a table where the entries in a column are before the current month value. So, if this month is January 2020, return the values before January 2020. Ideally it’s goi…

Group numbers by 45 in mysql

I have a database in which I store wind direction readings by degrees. I need to do two things really, i need to group all readings by 45 (basically 45 degrees between “N”, “NE”, “E”, “SE”, “S”,”SW”,”W” and “NW”) a…