I’m writing a REST api that works with SQL and am constantly finding myself in similar situations to this one, where I need to return lists of objects with nested lists inside each object by querying over table joins. Let’s say I have a many-to-many relationship between Users and Groups. I have a …
Tag: sql
sql query for stratified sampling with dynamic sample size
Let say we have a table in this format: From this example, we see two stratas s1 and s2. What I want to do is stratified sampling and the sample size is the last column. For example, I want to randomly sample 2 instances from s1 and 1 random sample from s2. Any help is appreciated. Please keep in mind
Updating a table in SQL Server with information from another table
I have a “claims” table. Each claim has a client attached to it which is represented by a few letters “ABED”. For some reason, the actual clientID is nowhere to be found in the claims table so I want to fix this. The “Clients” table DOES contain both the code AND clientID. …
MYSQL subquery results columns not as expected
I am trying to build a query that will build a output like this. The output that I go is this I was following the instructions here https://www.mysqltutorial.org/mysql-subquery/ My query is this What I was expecting to happen was the alias ‘patient appt’ to be populated with the data from the nest…
Get Name from characters that died on Episode3 with its killer
I have a doubt on this sql problem. Here is the tables. I currenly have all the characters names that died on Episode 3, but I don’t know how to get the character killers. Any idea? Select name from …
Is it possible to pick data from SQL in a Lua code?
I’m coding with Solar2d in Lua and I wanted to pick data from an SQL table. Is it possible? Thank you
How to refactor my python to use a SQL Prepared statement?
Code to accept input from the user and gives a User for a given username. Now it is accepting the input directly into the SQL query but I would like to use it with prepared Statements, how could I do …
count total no of people in school
database for school their are two main table student and teacher the creation of table is almost like this create table students ( students_id int, year int ) create table Teacher ( Teacher_id int, year int ) but i what to count total number of people(student + teacher) in each year. example students students…
Convert columns to rows and get the sum of checkboxes in Access
I have an Access database that has checkboxes in on of the tables. I need to get a Sum of the checkboxes but, I want to convert the checkbox columns into rows instead of columns. Here is an example …
Why do I get a conversion failed error when I use my attribute on my WHERE clause but it works when I don’t?
Why is my query returning a result when I run the following query: SELECT MAX(CAST(IssueDate as Date)) FROM (SELECT IssueDate FROM [Transient].[Commissions_TIB] WHERE ISDATE(issuedate) = 1 …