Skip to content
Advertisement

Tag: group-by

Invalid group by expression error when using any_value with max and window function in Snowflake

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:

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

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

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

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:

Advertisement