Viewing 15 posts - 286 through 300 (of 4,087 total)
WITH sales_by_team_and_category AS
(
SELECT
SUM(sales) AS Total_Sales
,Teams
,Category
,ROW_NUMBER() OVER(PARTITION BY Teams, Category ORDER BY SUM(sales) DESC) AS rn
FROM Sales
GROUP BY Teams, Category
)
SELECT *
FROM sales_by_team_and_category
WHERE rn <= 10
Drew
December 18, 2019 at 3:21 pm
Data should be stored in fields of the appropriate data type. Dates should be stored in date fields, not character fields. (There is an exception for intermediary tables that are...
December 17, 2019 at 10:02 pm
Having separate threads for each topic makes it easier to follow each conversation and also makes it easier Google it. I'm also having trouble understanding what questions you might have...
December 17, 2019 at 3:38 pm
Actually, why don't you just insert it into your first temp table instead of creating a second?
create table #HomeroomTeacher2 (TeacherPersonID int , sectionTeacherDisplay varchar(105))
insert into #HomeroomTeacher2 (TeacherPersonID...
December 12, 2019 at 9:48 pm
This only requires one temp table, which I think is what you are looking for.
create table #HomeroomTeacher3 (TeacherPersonID int , sectionTeacherDisplay varchar(105))
insert into #HomeroomTeacher3
SELECT TeacherPersonID, sectionTeacherDisplay
from HTeacher
UNION
SELECT...
December 12, 2019 at 9:44 pm
Your conditions are contradictory. You will NEVER get any records that meet all criteria. Since AND
is both commutative and associative, your conditions are equivalent to
(
...
December 12, 2019 at 9:33 pm
if you look at recursive CTEs you can build a list of dates within your boundaries
then use SELECT DATEPART (DAY,GETDATE()) and exclude the Saturday and sunday values then count...
i...
December 4, 2019 at 5:18 pm
drew.allen wrote:EXEC has been deprecated.
Drew
Have you got a Microsoft link that states this?
Note
This feature is in maintenance mode and may be removed in a future version of Microsoft SQL...
December 2, 2019 at 4:35 pm
Unless you are required to do this for legal purposes, it's more trouble than it's worth. Just assign identity or a date/time field when you create the record and then...
December 2, 2019 at 4:19 pm
You should be using sp_executesql
instead of using EXEC
. EXEC has been deprecated.
Drew
November 29, 2019 at 5:13 pm
Unless you are required to do this by law, it's more trouble than it's worth. If you absolutely have to do it, I would use a SEQUENCE
and run a...
November 27, 2019 at 7:31 pm
No solution is going to work here, because all solutions require a sort and there was no field provided that would ensure the correct sort.
This was and still...
November 26, 2019 at 8:56 pm
The following requires fewer scans, so it will perform better. It does depend on having the identity field with a primary key. You can use CHAR rather than BINARY as...
November 26, 2019 at 5:58 pm
Use the LAG function
https://docs.microsoft.com/en-us/sql/t-sql/functions/lag-transact-sql?view=sql-server-ver15
LAG()
is not going to work here, because it goes back a specific number of records and this solution requires going back an arbitrary number...
November 26, 2019 at 4:04 pm
First, simply stating that something "is not working properly" is not very informative. Are you getting an error message? Are getting wrong results? How is it not working?
Second, your sample...
November 26, 2019 at 4:00 pm
Viewing 15 posts - 286 through 300 (of 4,087 total)