I am working on an SQL Server procedure that I would like to have print the department name and students name Similar to the attached snippet The formatting should look like the attached sample snippet and there are two columns involved. students and department tables. The problem is that the results are inco…
Tag: sql
How to choose in postgresql rows where amount of one value is bigger than another? [closed]
Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 2 years ago. Improve this question how t…
How to write this SQL query more elegantly ( joining + max query )
Ok I am using the following example from w3school https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all and I want to get the date in which the amount was ordered This works but my guts tell me I need to use joining or having ?? Answer You want the date of the order that has the maximum quantity…
Query help in SQL
I have the below table, with empid, deptid, and Name. I need to get the results as empid,deptid,name and count of employees in each department. I need to get the results as empid,deptid,name, and count of employees in each department as below. I am able to achieve results using the below queries. Is it possib…
What is the type casting hierarchy in mysql?
Taking the following example: If I only include the first select statement in the cte, the type will be int. If I include the first and second, the type will be DECIMAL, and if I include all three, the type will be cast to VARCHAR (regardless of position of the three statements). How does mysql determine whic…
Mysql Conditional Aggregation Using group_by query and Case to group Month and Year
I’ve a table structure where I’m saving the data in the below format. The ledger amount needs to be divided into two columns and grouped through the sum equation. Those rows having receipt_id not as null their ledger_amount needs to be displayed as sum(ledger_amount) as credit whole rows having pa…
SQL sort and count duplicate value
I need to count and sort student, how many course they took based on level like this: ID|NAME |Point1|point 2|point 3| 1 | Tom | 3| 3 | 1 | 2 | Jer | 5| 0 | 6 | I have 3 table …
How do I make sure that all rows with the same foreign key have unique names in my PostgreSQL database?
I have a PostgreSQL database with two tables: Team and Project, in a one-to-many relationship. Team has these columns: id name Project has these: id name team_id I’d like to make sure that the projects within a team must have unique names. Projects belonging to different teams should be able to share na…
Get one record per ID
I’m trying to retrieve data from 2 tables A&B. , there are multiple data rows in B for each PrimaryKey from A. But I want to get only the first record for every ID from tableA. How can I achieve this? Answer SQL tables represent unordered sets so there is no first row. But you can get an arbitrary r…
Update partial jsonb field in Postgres 13
can anyone help please optimize SQL request Postgres 13 (jsonb). Need to update the “percent” values inside the Jsonb field with the specified ID This example is working, but it works for a very long time on a large database. https://dbfiddle.uk/?rdbms=postgres_13&fiddle=a521fee551f2cdf8b189ef…