I have the following data: Then i do the following query: The result is correct: Then i add two column, name and value: That return: What i expect is: If i add group by on guid_count, cuid_count, and umdid_count: How to overcome this problem? Could you help point me where my mistake is? Thank you. Answer You should use an
Tag: group-by
Group rows by dense_rank() and loop through each sub-group and compare another column in next row of that sub group?
I have tried the following in LINQPad: I want to write a query which will return only the IDs 1 and 2 (not 3 and 4) because: ID 1 – has more than 1 rows and startdate of its rownum 2 is 1 day ahead of enddate of its rownum 1 ID 2 – has more than 1 rows and
Select with IF statement on postgresql
I have a code like that: select tbl.person ,COUNT(distinct tbl.project) ,if (tbl.stage like ‘%SIGNED%’) then sum(tbl.value) else ‘0’ end if as test from my_table tbl group by 1 And …
Query to “PIVOT” the results of SalesAmount & CumulativeMonthly for specific YEARS
I have a database table that captures every Sales Transaction: Transactions ( ID INT, TransactionDate DATETIME, SalesAmount MONEY ) I need to run a T-SQL query to produce a Sales …
MYSQL : Group count specific column per user?
I want count column per specific user, using data from 3 tables. TABLE 1 (users) : SAMPLE : TABLE 2 (data) : SAMPLE : TABLE 3 (access): SAMPLE : What i tried so far : Result : I what to link it with user name alse, Desired Result : Answer Seems you need also a join for users and as
Aggregate Function Error With Basic Query
My database is based on a cinema, I am trying to make a query which displays the number of tickets purchased for each movie screening. The tables involved in this query are Bookings, Screenings and Movies. Here is the Bookings table: The Screenings table: And the Movies table: I have so far managed to get the query to the point
How do i make a sql query using more than one tables with onde condition for each?
i want to get some data from a table but separated by different conditions, for example how many lines have a column are equal to 1, how many have a column equal and the same until the number 5. i did …
How to display the related records in a single row in Oracle SQL?
I wrote a query joining two tables and I got a below resultset: However, I need to display below output with one new field called ‘Status’.Mark can work in both the departments and so the count is “2” and the status will be ‘Y’ ( displaying of any one record is okay) . Justin works in only one department and
PostgreSQL multiple join
I would like to make multiple joins in one query, I have four tables for that with the following structure: Table 1 fields, t1: did (int), finished (datetime), userid (int) Table 2 fields, t2: userid …
SQL join and Bring in 1 column into 2 columns
I have two tables shown as above. I want to create a select statement that would have the following result: Basically, I want to join on ‘Model’ and ‘Num’ columns and bring ‘Val’ vales but break it …