I am attempting something very similar to last example (Using GROUP BY) on this page: https://thecodedeveloper.com/mysql-count-function/ Referring to the following table of data: The following query: Will produce the following output: Except I want to see the number of employees in each department as well as …
Tag: sql
How to structure the database to avoid duplicates in a table
I am doing this exercise where I have to build an sql database (MySql) to store information on private lessons offered by teachers. These are the rules: There is just one predifined week with slot times from Monday to Friday (15-19) Each teacher can teach 1 or more courses Each course can be teached by multip…
How to successfully reference another table before insert with a trigger
I’m trying to create a trigger to validate if a new entry in the table registraties (registrations) contains a valid MNR (employee number) but I’m getting stuck on the part where I’m referencing the table medewerkers (employees). Could someone help me out? Error message received is ORA-24344…
how can i check if value exists before the date specified in sql server
I have the data below in a sql table, let assume the user wants to get data of 2020-11-13 which is but i’d like to get the previous supplier due as well before the date specified which is along with so the actual query i wanna get is this and if there is no previous due i wanna return i
SQL new table with conditions
I have a table and I want through sql to parse it into another table. The problem is that there is a condition: There are 3 columns in old version And I want to store them into new table’s column like : Thanks in advance. Answer You can use case expressions and string concatenation, like so: This uses s…
Presto – pivot table
Hi I have a table like this: I want to convert it into like this: Answer For a fixed list of properties, you can do conditional aggregation: This puts the session id in the first column and 0/1 values in each column, depending on whether the given session owns the given property. To generate the exact output …
Why does the DBMS say that the primary key is not present in the table
I am a CS student that is taking his first course in databases so here I am using Postgresql to create a database with the following tables: employee, project, and worksOn. So if you run the program you can see that both the employee and project table are created. However, worksOn is not because it gives me t…
How to fill irregularly missing values with linear interepolation in BigQuery?
I have data which has missing values irregulaly, and I’d like to convert it with a certain interval with liner interpolation using BigQuery Standard SQL. Specifically, I have data like this: # data is …
SQL syntax query order by
SELECT TCID, START_TIME, RESULT, cast(START_TIME as date) as m_date, max(cast(START_TIME as time)) as max_time FROM jenkins_result.JENKINS_RESULT WHERE TCID = ‘A330506’ GROUP BY TCID, …
Model hierarchy in Django [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question Sorry for the long text Models are given: User Hierarchy class Hierarchy (…