I was given a query and I am attempting to modify it in order to get the most recent version of each COMP_ID. The original query: I then attempted to use a window function to grab only the highest version for each comp_id. This is the modified query: When attempting to compile the below error is given: SQL compilation error:
Tag: group-by
GROUP BY Subquery returns more than one row
I’m looking for a way to solve the following situation. I have a table that I need to return only one number for each “p.pays”, This query is supposed to list “nom from table Pays” where at least half of the “athlete” have are in the table “Resultat” but my subquery returns more than one line is there a way
Presto lag dates, group/partitioned by id
Say that I want to find every time that a client updated their budget. Here’s what my data looks like And the code I’ve run. What I’m expecting returned will be Hence there are NULL values for dt_2 in the first entry of each client_id. I’m not sure what code will accomplish this effect; is a GROUP BY clause will
grouping equal values – aggregate function problem
I’ve created a table that lists venues in which several events take place. The same event in the same venue can have a different price. The last column calculates the total revenue for one venue. venue event totalprice sum Venue A Event A 5 30 Venue A Event A 10 30 Venue A Event B 5 30 Venue A Event
Is there a way to count and calculate percentages
In this image, I would like to count the occurrence of header5 for each header1 group. Plus I want to know the percentage of each occurrence in header5 for each of the elements in header1 Answer Try this:
SSMS SQL Identify purchases who only buy one specific item
I want to find customers who have only bought fruit in their purchase. My data looks like this: I want this: Thinking I need a where clause, grouped by ID and Purchase_date? Answer You can try to use Having with condition aggregate function to write the logic. Buy fruit (COUNT with fruit count will be greater than 1 ) Din’t
filtering using having by clause result in unknown column in having clause
i have a table with these columns: order_date (in yyyy-mm-dd format), order_status, product_sub_category, sales. the data consists of transactions from 2009 onwards. what i want to do is to find the total sales of each product categories in between the year 2011 and 2012. to do that, i use these query: the problem is that sql tells me unknown column
Group By function
hope you all having a great day. I need some help with this query. Just to explain the situation, I have to send e-mails containing the data found in this select, but I have to group by customers (TBLOTE.CEMPRES) so it would build a single e-mail for each customer found. Example, if the query finds 3+ row for customer ´John
If there are several Positions, then find only the main one, otherwise take another
Need to filter the records so that the employee mostly has only the position with the employment type 0. I can’t just do where TypeEmployment = 0, because it will cut off the employee with private face id 3406 But I would like to see him, because he does not have a position with type 0 However, the employee with
How to multiply two columns and add a new column to the database?
Which customer id bought maximum products? (hint : get sales by multiplying product_quantity and price_per_item fields) This is how the database looks like After adding the sales column I am not able to perform the sum operation and getting the following error: SELECT customerid, product_quantity * price_per_item as “sales”, SUM(sales) FROM questions GROUP BY customerid LIMIT 0, 1000 Error Code: