I am trying to retrieve details about stores where their average product prices are higher than the average of all stores in the table. So far, I have this code: select StoreID, count(ProductID) …
Tag: group-by
SQL group by is bringing lots of duplicates
I’m trying to group my data by OccDate, ParkingContextType, AuthorityId and of course, i would like to measure each sessions for each date/contexttype etc… However, I`m also trying to calculate the …
group by issue in sql
i’m trying to get in a new column the sessions who are between 08:00 and 18:00. You can see my last CASE in the CTE. For each date there should be a new column “TotalRestrictedSessions” which indicate how many session were on that particular date. If there are none, in this case i have to write 0. I suspect that
Group by multiple columns and limit per group – Postgres
I’m creating a messaging app as a side project and I’m trying to query a user’s conversations efficiently. The messages table structure is basic right now with some dummy data: I’d like to be able to query the DB and group by “conversation” – A.K.A any rows that have the same sender_id or receiver_id in either column – rows (1,
How do I do SQL sum across a table diagonally?
I have this table: I want to get this: The idea is to sum up the Col B of Quarter 1 with Col C of Quarter 2… and group by Col A Answer Very strange, but you can use conditional aggregation:
Convert different dates in date column to rows in SQL Server
I want to display different dates as columns from LOGDATE column. Here are the details My query: This query returns this result: Expected output format: I have multiple types of SERVICE_TYPE and SERVICE_NAME, not just the three sown in the sample. How can I get my expected output? Any help would be appreciated. Answer You can do conditional aggregation to
Find the manager details where all the employees under the manager should have salary more than 1000
Im having the table with records like below and i need to get the manager details where the all the employees under the manager should have salary more than 1000 Answer Here is a solution that uses a correlated subquery: This ensures that: the selected employee is a manager (ie they manage at least one employee) all of the managees
What is the difference between count (*) and count(attribute_name)?
Is there any difference between COUNT(*) and COUNT(attribute_name)? I used count(attribute_name) as I thought that it would be specific hence the searching process would be easier. Is that true? It would be great to see any example with sql code with my issue to help me understand better Answer Imagine this table: count(column_name) also counts duplicate values. Consider:
SQL statement about average
My question is -> Retrieve the segment ID and length of each segment that is longer than the average length of all segments. Name the column indicating the length of segments “Length”. Relations: What I got so far is: And I got this error message: Error: Your query has syntax errors. Description: java.sql.SQLException: ORA-00979: not a GROUP BY expression Can
Get the highest category while performing other type of aggregates
Story: I am trying to get the sum of records and the max date by country and games and another column that would rank the top countries based on the sum of records: It is the country rank column that is giving me trouble. Here’s what I tried: All it does is rank the each row partition by country which