Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have 2 tables: STORES & REPORTS. The common key is the store_id
See attached image...
I want to build an SQL statement in a way to give me the total (SUM) of daily sales, daily visits and daily questions for each store separately.
Is there any way to do that, in a way that I will be able to loop through (move.next) in each store so to have the totals of each one store in one line?
You can try this query --
select
s.store_name,
sum(r.[daily sales]) as [daily sales],
sum(r.[daily visits]) as [daily visits],
sum(r.[daily questions]) as [daily questions]
from
stores s
left outer join
reports r on s.stored_id = r.store_id
group by
s.store_name
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 days ago.
Improve this question
I have, for example, ten customers
each customer placed ten orders
I would like to make a query to get the last order for each customer.
I would like to have it as a Google formula
=query
But I don't know the select what I need to enter.
Try below formula-
={UNIQUE(A1:A),
MAP(UNIQUE(A1:A),LAMBDA(x,INDEX(SORT(FILTER(A1:C,A1:A=x),3,0),1,2))),
MAP(UNIQUE(A1:A),LAMBDA(x,INDEX(SORT(FILTER(A1:C,A1:A=x),3,0),1,3)))}
Edit: With QUERY() formula-
=QUERY(A1:C,"select A, max(B), max(C) where A is not null group by A label max(B) '', max(C) ''",0)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 11 months ago.
Improve this question
SELECT Nimi
FROM Myyjad
WHERE Myyjad.KauplusID
IN (SELECT KauplusID
FROM Kauplused
WHERE Kauplused.Kauplus = [Kauplus?])
AND Myyjad.Vanus > 60
ORDER BY Myyjad.Vanus DESC;
The initial task is: By the name of the store (through the parametric window), display the names of the oldest customers of this store.
I need condition where Myyjad.Vanus is the biggest (I can't use MAX func).
Please check relationships in on the link below.
relationships
sample1
sample2
SELECT TOP 1 Nimi
FROM Myyjad
WHERE Myyjad.KauplusID
IN (SELECT KauplusID
FROM Kauplused
WHERE Kauplused.Kauplus = [Kauplus?])
ORDER BY Myyjad.Vanus DESC;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
My data set has a weight column and a variable of interest var1, for which I need to form a weighted average of all rows that satisfy either var1=1 and var1=2. Unfortunately I need to do this in SQL, where I have very limited knowledge. To compute the weighted average of all rows, I would write SUM(var1 * weight)/SUM(weight). But how can I do this computation for all rows where var1 IN (1,2)?
It seems like what you're looking for would be the following:
SELECT SUM(var1 * weight) / SUM(weight)
FROM sample
WHERE var1 in (1,2)
I created a dbfiddle where you can go and check it out.
https://www.db-fiddle.com/f/qytaC3augXijw956ReuYqb/1
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
i want to set a filter for my product list so when the user set the shop name is shows only the products of that selected shop and when he also sets the Price limit it show the products of that same selected shop but with that desired price limit too
my sql request is like this but they told me it's wrong :
select nom from produit where boutique_id=3 or ( boutique_id=3 and Prix<500)
if there is any way i can do what i need to do please tell me
Is this what you want?
select nom
from produit
where boutique_id = 3 and (Prix < ? or ? is null);
The ? is the placeholder for your price parameter.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am trying to get products groups that have products with a PRODUCT_AGE less than 12 months old.
Here is my current query:
SELECT MIN(SHIP_TABLE.SHIPDATE) FIRST_SHIPPED, PRODUCT_TABLE.PRODUCT_GROUP_ID,
DATEDIFF(MONTH,MIN(SHIP_TABLE.SHIPDATE),GETDATE()) PRODUCT_AGE
FROM SHIP_TABLE
LEFT JOIN PRODUCT_TABLE ON PRODUCT_TABLE.PRODUCT_ID = SHIP_TABLE.PRODUCT_ID
WHERE SHIP_TABLE.PRODUCT_ID BETWEEN '101000000' and '999999999' AND
PRODUCT_TABLE.PRODUCT_GROUP_ID IS NOT NULL AND
DATEDIFF(MONTH, MIN(SHIP_TABLE.SHIPDATE),GETDATE()) <= 12
GROUP BY PRODUCT_TABLE.PRODUCT_GROUP_ID
ORDER BY PRODUCT_TABLE.PRODUCT_GROUP_ID ASC
This query returns an aggregate error.
I've tried using a subquery; but, couldn't get it to work either.
The SHIP_TABLE lists the dates of all products; while, the PRODUCT_TABLE lists the Products and their product groups.
What am I doing wrong? How can I get my query to properly filter?
When you have MIN(SHIP_TABLE.SHIPDATE) FIRST_SHIPPED and DATEDIFF(MONTH,MIN(SHIP_TABLE.SHIPDATE),GETDATE()) PRODUCT_AGE, I believe you are trying to use aliases. This is incorrect syntax. Aliases are used with the as keyword:
MIN(SHIP_TABLE.SHIPDATE) AS FIRST_SHIPPED
DATEDIFF(MONTH,MIN(SHIP_TABLE.SHIPDATE),GETDATE()) AS PRODUCT_AGE
In your where-clause you have:
DATEDIFF(MONTH, MIN(SHIP_TABLE.SHIPDATE),GETDATE()) <= 12
I believe this will cause an error; probably, your aggregate error. You should use a having clause. See this post for more information.