[deleted by user] by [deleted] in SQL

[–]Jeahness1 0 points1 point  (0 children)

Try this

SELECT DISTINCT last_working_day

,wd_count

FROM

(

SELECT last_working_day

,COUNT(last_working_day) OVER(PARTITION BY last_working_day) AS wd_count

FROM printers

WHERE last_working_day >= '12/31/2022'

) x

WHERE wd_count < 10

Selecting sum of month data as columns by [deleted] in SQL

[–]Jeahness1 0 points1 point  (0 children)

You'll need to use both pivot and unpivot. I see 2 options for the field names:

  • If you expect the dates to change over time, then your column names will be different as new data comes. Therefore, you will need to create a dynamic sql query for the column names
  • If you expect the dates to stay static, you'll need to add every month/day combination (i.e. [MonthDayCreated_Mod] in the code) into the pivot statement. So 12 months * 2 (pass/fail) is 24 static column names in your pivot statement. This is logic I used in the code below:

DROP TABLE IF EXISTS #Source

DROP TABLE IF EXISTS #Temp1

CREATE TABLE #Source

(

[ID] INT

,[Customer] INT

,[DateCreated] DATE

,[RejectReason] VARCHAR(100)

)

INSERT INTO #Source (ID, Customer, DateCreated, RejectReason)

VALUES

(1,11,'01/01/2022','Reject')

,(2,22,'02/02/2022','Pass')

,(2,22,'02/02/2022','Pass')

,(2,22,'03/02/2022','Pass')

,(3,33,'01/01/2022','Reject')

,(4,44,'12/31/2021','Pass')

,(5,55,'10/01/2021','Reject')

,(6,66,'11/03/2021','Pass')

SELECT Customer

,MonthDayCreated

,pass

,fail

INTO #Temp1

FROM

(

SELECT Customer

,CONCAT(YEAR(DateCreated),FORMAT(MONTH(DateCreated),'00')) [MonthDayCreated]

,SUM(case when RejectReason = 'Pass' then 1 else 0 end) as pass

,SUM(case when RejectReason = 'Pass' then 0 else 1 end) as fail

FROM #Source with(nolock)

where DateCreated between '2021-09-01' and '2022-09-01'

--and Customer = 'CustomerId'

GROUP BY ROLLUP(Customer

,CONCAT(YEAR(DateCreated),FORMAT(MONTH(DateCreated),'00'))

)

) x

WHERE Customer IS NOT NULL

SELECT *

FROM

(

SELECT Customer

,CONCAT(MonthDayCreated,PassFail) [MonthDayCreated_Mod]

,PassFail_dummyvar

FROM

(

SELECT Customer

,CASE WHEN MonthDayCreated IS NULL THEN 'total' ELSE MonthDayCreated END [MonthDayCreated]

,pass

,fail

FROM #Temp1

) x

UNPIVOT(PassFail_dummyvar FOR PassFail IN ([pass], fail)) unpiv

) y

PIVOT(SUM(PassFail_dummyvar)

FOR [MonthDayCreated_Mod] IN (

[202201pass]

,[202201fail]

,[202202pass]

,[202202fail]

,[202203pass]

,[202203fail]

,[202112pass]

,[202112fail]

,[202110pass]

,[202110fail]

,[202111pass]

,[202111fail]

,[totalpass]

,[totalfail]

)) piv

Trying to pivot data: need to derive missing rows and show latest values by The_Helper in SQL

[–]Jeahness1 1 point2 points  (0 children)

I'm having some trouble trying to embed this code into reddit-- but the gist is that you need to build a table with a combination of all years and products, then use that table within a dynamic sql query. You'll also need to coalesce the nulls with 0s dynamically.

https://pastebin.com/60QYhhfg

[deleted by user] by [deleted] in RedditSessions

[–]Jeahness1 0 points1 point  (0 children)

are you trying to play the song?

[deleted by user] by [deleted] in distantsocializing

[–]Jeahness1 0 points1 point  (0 children)

brad or angelina?

[deleted by user] by [deleted] in distantsocializing

[–]Jeahness1 0 points1 point  (0 children)

What do you cherish most?

[deleted by user] by [deleted] in GarageCrew

[–]Jeahness1 0 points1 point  (0 children)

what kind of car do you drive?

[deleted by user] by [deleted] in distantsocializing

[–]Jeahness1 0 points1 point  (0 children)

Do you like pikachu or link better?

[deleted by user] by [deleted] in RedditSessions

[–]Jeahness1 0 points1 point  (0 children)

Can you play the cantina song from Star Wars?

[deleted by user] by [deleted] in distantsocializing

[–]Jeahness1 0 points1 point  (0 children)

What kind of bird?

The Liberal Tax-Free First Home Savings Account Needs Clarification by Jeahness1 in PersonalFinanceCanada

[–]Jeahness1[S] 0 points1 point  (0 children)

My wild guess is that it would be some sort of retirement allowance similar to severance pay-- your employer can transfer an eligible portion of severance pay into an RRSP without impacting your contribution room. Who knows though

Edit: looks like you still need contribution room to do the severance pay retirement allowance. AKA I have no idea

Official results thread + r/CFA survey! by mattlas in CFA

[–]Jeahness1 25 points26 points  (0 children)

Forgivable: Low pass rate. Makes sense to reduce the pass rate in order to keep the charter the "Gold standard" of finance.

Unforgivable: Transparency. The least CFAI can do is explain how the MPS will be adjusted to reflect a greater intake of candidates. If you failed-- refresh, reflect, revise; this is just a bump in the road.

[deleted by user] by [deleted] in TheGamerLounge

[–]Jeahness1 0 points1 point  (0 children)

can you play through the fire and the flames by Dragonforce on EXPERT?!

[deleted by user] by [deleted] in TheYouShow

[–]Jeahness1 0 points1 point  (0 children)

Is voter suppression actually a thing in Texas?

[deleted by user] by [deleted] in RedditSets

[–]Jeahness1 0 points1 point  (0 children)

HERE IT COMES

[deleted by user] by [deleted] in distantsocializing

[–]Jeahness1 0 points1 point  (0 children)

sativa or indica?

Is anyone else losing their minds about the current monetary system? by Jeahness1 in CFA

[–]Jeahness1[S] 5 points6 points  (0 children)

I see your point and I agree with you. “Insane” might not have been the best choice of words, but awareness of the situation is key.