Skip to content

Tag: sql

How to add a sum column with respect to a group by

I have a table1 : And i want to add a column wich sum the count column by grouping the first two variables : this is what i do : then : But i have a feeling this is a sloppy way to do it. Do you know any better ways ? For example with no intermediates tables. edit :

PostgreSQL – Insert data into multiple tables simultaneously

I am having a data insertion problem in tables linked by foreign key. I have read in some places that there is a “with” command that helps in these situations, but I do not quite understand how it is used. I would like to put together four tables that will be used to make a record, however, that a…

Executing a SQL query with C#

I would like to add some information to my database. I searched for some tutorials, but none of them work. NonQuery can do what he needs to do, because the messagebox returns “Success” (1). But it does not update my database. If I put the same query to “Add New Query”, directly to my d…

Find name of manager with max number of subordinates

I need to write SQL query (for Oracle) which displays name of manager with max number of subordinates. Table’s structure: MGR_ID employees’ attribute is an EMPNO(primary key) of manager. What I’ve tried so far: Answer Another version suggested by a_horse_with_no_name PS : Query Not Tested

Symfony doctrine orderby and group by (distinct)

I am trying to get the latest booked courses (unique). I have tried the following with the Doctrine querybuilder: Without the orderby it works but it will traverse the bookings ascending. I need the latest booked courses. With this query I am getting this error: SQLSTATE[42000]: Syntax error or access violati…

Limit SQL Primary Key to certain ranges

I want to make the autoincrementing Primary Key of my table to only be in the ranges 1-12, 101-112, 201-212, etc. This is because I have a series of repeating items that are 12 in a set and then you get another set, having them indexed in this way by the Primary Kay would be most easy, I think. Is