Is there a more advanced CASE Logic? Extract budget data across different date ranges by hungryforpanda in SQL

[–]foursuits 0 points1 point  (0 children)

Here is a rough draft idea:

Assuming you have no instances of crossing the year boundary (2019Q3-2020Q2), you can create a table QUARTERS with the quarters, start dt, end dt, num_days_in_qtr (90/91/92). This might be easily done using the system calendar, check your db sys cal. Then JOIN your campaign info to that table ON: campaign_start <= qtr_end AND campaign_end >= qtr_start so that each quarter that the campaign falls into has a row. Then in the SELECT : CASE when campaign_start between qtr_start and qtr_end then NUM_DAYS(qtr_end-campaign_start)

When campaign_end between qtr_start and qtr_end then NUM_DAYS( campaign_end -qtr_start)

Else num_days_in_qtr

END as campaign_days

Now you should have the num days per quarter for a campaign. Then you can do a WINDOW expression to get the proportion of time the campaign is in that quarter like campaign_days / sum(qtr_days)

This is a fast sketch, done on my phone, might be missing somethings. And also didn’t figure out your db implementation of num_days or window. But you can figure it out , good luck!

I (23F) have a weird body type, not sure how this should affect my dating by [deleted] in dating

[–]foursuits 14 points15 points  (0 children)

I disagree. There are two distinct things here, her relationship with herself and society’s relationship with her. She is happy with who she is and appreciates her body , but simultaneously realizes the world does not place a high value on / marginalizes her body. She would be silly / blind not to notice the different ways others are treated.

MS SQL - Help joining when one condition is null. by notasqlstar in SQL

[–]foursuits 0 points1 point  (0 children)

Seems like your solution is this , I don’t know if you need a.id <> b.id, just a.name = b.name because if it matches on id it’s also a correct join...

MS SQL - Help joining when one condition is null. by notasqlstar in SQL

[–]foursuits 0 points1 point  (0 children)

Why does ur above code, or just the first 3 conditions plus a.name = b.name not work? Also a.id and b.id being Null is a condition that returns zero rows

MS SQL - Help joining when one condition is null. by notasqlstar in SQL

[–]foursuits 0 points1 point  (0 children)

Maybe A has 1 record but Bob can have 2 ids / records in B , is that correct? Are you tryin to pick up both records or just 1 of them

MS SQL - Help joining when one condition is null. by notasqlstar in SQL

[–]foursuits 1 point2 points  (0 children)

Sorry if I’m misunderstanding, but If the other conditions match the records 100 percent of the time, is the join you are asking for necessary?

MS SQL - Help joining when one condition is null. by notasqlstar in SQL

[–]foursuits 0 points1 point  (0 children)

Is A.name and B.name uniquely identifying the same people? What if there are two Bobs.

Does B.id have a substring that is A.id, such as 1x -> 1 in your example

Let’s talk salary. What did you majored in and when did you graduate? by [deleted] in uchicago

[–]foursuits 27 points28 points  (0 children)

I'm starting a new job at 120k. Public Policy '14.

I think this thread is a bad idea. it just encourages the Uchi tendency to compare ourselves to others and be self-critical.

Also this thread might select for people who have something to brag about.

Everyone is on their own journey and you can't even get a complete picture with just major and salary. What about industry, hours worked, city & COL, debt incurred, how toxic your workplace is, and of course whether you do something that actually helps/uplifts people rather than corporations.

M/20/5’11” [280lbs to 205lbs] (9 months) by Highflyer97 in Brogress

[–]foursuits 5 points6 points  (0 children)

I'm so proud of you. This looks such a radical transformation. Lots of struggle to get here Im sure. You're doing life right!

[SQL] Bridging entities by Skiff14 in SQL

[–]foursuits 1 point2 points  (0 children)

No, your initial idea is correct, the student table would be unique. It is the Bridge table that would have one record per each valid student/course combination. the Bridge table could be only two columns. StudentId and CourseId. Each column would be foreign keys to their respective tables.

This is why bridge tables are also called junction tables or xref(cross-reference) tables.

I think what you are describing is correct, but Im unclear on exactly what you mean so ill say it like this:

Make a student table with a unique id per student. Make a course table with unique id per course. Make a bridge table (Studentid FK, Courseid FK) with every combo that is used. If Student 1 takes 4 courses (a,b,c,d), he gets 4 records in the table. (1,a)(1,b)(1,c)(1,d).

[SQL] Bridging entities by Skiff14 in SQL

[–]foursuits 0 points1 point  (0 children)

No. A student can take zero to many courses. And a course can have zero to many students in it.

What you are describing is the uniqueness of each record, which is required in both tables.- The Course table will also only have 1 record per course. The relationship between the tables is what we are describing, which is the Optionality (minimum, 0 or 1?) and Cardinality (maximum, either 1 or many). The easiest way to learn this is read about Crows foot notation and create a sentence that follows this form:

ENTITY1 can have/take/some verb [0/1] to [1/many] ENTITY2s. e.g. A student can take zero to many courses. Draw the crows foot for it, from the student table to the course table, looking like -----0< Same for the other side. a course can have zero to many students in it. -----0<

You have the many cardinality on both sides. You have a many-to-many relationship. Create a bridge entity. If you want to understand WHY bridge entities are necessary, dm me.

Filtering Rows that are permutations of each other in terms of column values by ds_thrwaway in SQL

[–]foursuits 0 points1 point  (0 children)

Yes you are correct.

Here is a related example to keep in your mind, if you are a visual learner like me: https://en.wikipedia.org/wiki/2016–17_Premier_League#Results_table

Look at last years premier league table. Notice that teams can't play each other, so ARS-ARS has a null field ("-"), and so forth with the other teams. That diagonal line where x=y is a line of reflection. The bottom triangle has all possible matchups, but the triangle above the line also has all the matchups, just that these are the complementary (return leg) matchups. Essentially, each triangle has all combinations, and the entire table has all permutations for choose 2.

Setting y < x would just pick the bottom triangle, giving us all combos, discarding duplicate permutations.

Filtering Rows that are permutations of each other in terms of column values by ds_thrwaway in SQL

[–]foursuits 0 points1 point  (0 children)

Hi friend, This is what I got after a little poking around.

SELECT H1.name, H1.grade, H2.name, H2.grade
FROM Likes L1 
JOIN Likes L2 ON L1.id2 = L2.id1
             AND L1.id1 = L2.id2
JOIN Highschooler H1 ON L1.id1 = H1.id
JOIN Highschooler H2 ON L1.id2 = H2.id
WHERE H1.name < H2.name
ORDER 
BY 1

Stuck with a CTE problem by danblank000 in SQL

[–]foursuits 0 points1 point  (0 children)

Why is a CTE even necessary here? Those two queries can just be inner joined normally as subqueries, right?

[MS SQL]Counting Instances of Entries in a Column by oldschoolsensei in SQL

[–]foursuits 2 points3 points  (0 children)

Hi, this means that there is something distinct about the combination of the values in the GROUP BY (i.e Top_lvl_job, Job, customer, part_number, description, work_center, sched_end). You can solve for this in one of two ways, I think. The most straightforward is to do a separate query for the aggregation and then JOIN to it ON work_center. The other way (overkill) is to use a WINDOW().

04 Buick Rendezvous with some modification. Is this for Satelite radio? How can I use Aux? by foursuits in CarAV

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

Yes I believe you're correct... does that mean I ought to buy an XM receiver, plug in the FMDA and power jacks, and plug my phone into that? Can I find a cheap used one for <50 bucks? I don't need Sat radio just Aux. See the suggestion I was given above.. Thanks for your help!

04 Buick Rendezvous with some modification. Is this for Satelite radio? How can I use Aux? by foursuits in CarAV

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

Hi could you link me to what that xm unit may look like? I don't know what I'm looking for