I have a table which lists equipment with an installation date. These items need to be serviced annually or every five years. So the rows have a service interval of 1 or 5. Something like: What I need to do is return a list of equipment two months before they are due for service For simplicity Let’s ass…
Tag: sql
Capture values from a table and declare as a local variable in SQL Function
I’m learning how to write functions in SQL and this might be simple but can’t seem to find what I’m looking for. I have a function as follows: CREATE OR REPLACE FUNCTION A.aggregate(r_id text) …
How to return a key value ONLY if ALL the foreign keys in another table have a certain status (ORACLE)
How do I return the key (not a primary key): bwb_procesinstantie_id of the table wachtbox ONLY if ALL ‘foreign key’ values in the related table status have the status = “B” Functionality: A process contains several rel_code. But the process can only be further processed if all the rel_…
Hierarchical SQL query to Athena
I’m trying to create a query in Athena that solves this problem: I have records that look like this which create a hierarchical structure, like a tree but with indeterminate children. I have more than one root, that is, more than one element that is not children of anyone. I want to get the complete str…
How can I echo the position number of SQL row in PHP?
Before you misread the title… I’m not asking how to echo the number of rows, I’m simply looking to find the position that the row is in. Let’s say we have five total rows: Now I’d like to get the position of the row that contains the post ID of 718. From looking at the data, we c…
Accessing array elements in query postgres
I’m currently building a query to retrieve some data from my db, I need to access the documents stored in an array, this is how the table crm_company looks: I have another table for users by document crm_user which looks like this: What I want as a final result is: I just have tried somehing like the fo…
Select max value for each company in list, display longest value per company per day
I’ve looked at some of the other questions similar to this, but nothing I’ve found can quite get me there. I have a table with multiple columns, but 3 of the columns are Company, Date, and WaitTime. I want to select the longest WaitTime for each company and for each day. I’d like to display …
Update column values with dynamically created JSON MySql
I have a Relationships table that looks something like this And 2 tables From and To I’m trying to update the JsonPair column with Json objects in the form {FromName: ToName}. So the resulting table would look like I’m a novice at SQL. I’m thinking that I should SELECT the names first, then …
Django get objects that are foreign key of two models
I have the following three models where Budget and Sale both contain a foreign key to Customer: I want to get a queryset of all Customer objects for which both a Budget and Sale exists. I initially tried getting the intersection of the customer field of all Budget and Sale objects: This returns the correct ob…
is “SELECT fieldname, fieldName FROM MY_TABLE;” ever valid for any SQL database?
Do any SQL databases have case-sensitive naming for field names? What I mean is, in Java you can have two variables … Are there any SQL databases support that so … … would return two different columns? I’m asking because I’m building a database utility that has to work for MySQL,…