Quick T-SQL Help Please

Not sure what climbed up your ass this morning. I was looking for some assistance, which some kind people provided.

Didn’t know when we ask questions on the forum we now need to provide a budget.

What’s worse is that he’s charging people R850 an hour for terrible solutions.
 
My sub-optimal query on page 2 has been bothering me
In terms of efficiency, will this be better?
Code:
SELECT Name,Positive,Negative,CASE WHEN Positive > negative THEN 'Positive' ELSE 'Negative' END MaxStatus
FROM 
(SELECT NAME,TYPE,id FROM RESULTS)x
PIVOT
(COUNT(id) FOR TYPE IN ([Positive],[Negative]))p

edit:
or

Code:
SELECT  DISTINCT NAME, TYPE FROM
(SELECT R.NAME,R.TYPE, 1.0 * COUNT(*) OVER (PARTITION BY NAME,TYPE) / COUNT(*) OVER (PARTITION BY NAME) AS PERC FROM RESULTS R
) R WHERE R.PERC > 0.5
 
Last edited:
Not sure what climbed up your ass this morning. I was looking for some assistance, which some kind people provided.

Didn’t know when we ask questions on the forum we now need to provide a budget.

Yep, as did I, but what it looks like is that you're looking for someone to tell you exactly how to write your query instead.

There has been many examples of how to approach and solve the problem you're experiencing. It's up to you to interpret those examples and apply them on your own to see what best fits or give you that "aha" moment to then go forward and implement, instead, you would want us to follow your exact requirements and/or tell us we're wrong with what we suggested until you have a well-formulated answer? Naw bro... that's why I charge for work if you need a solution. Always glad to help and push into the right direction, but not really interested in the attitude where you expect someone to do your work for you, much like how much of SO has evolved into. And yes, I need to remember to go buy some dip for the chip on my shoulder
 
Yep, as did I, but what it looks like is that you're looking for someone to tell you exactly how to write your query instead.

There has been many examples of how to approach and solve the problem you're experiencing. It's up to you to interpret those examples and apply them on your own to see what best fits or give you that "aha" moment to then go forward and implement, instead, you would want us to follow your exact requirements and/or tell us we're wrong with what we suggested until you have a well-formulated answer? Naw bro... that's why I charge for work if you need a solution. Always glad to help and push into the right direction, but not really interested in the attitude where you expect someone to do your work for you, much like how much of SO has evolved into. And yes, I need to remember to go buy some dip for the chip on my shoulder

Dude I got the initial OP wrong with my wording and subsequently apologized and updated it.
Asking if your HAVING clause would exclude records is a valid question.

@skimread posted his intepretation and I got the aha moment you mentioned from the ROW_COUNT, which was implemented and is working.
The query I needed help with is a sub-set of a bigger one which is why I was looking for other options, which were provided, so I'm not exactly sure were you get off on saying people are doing my work for me.

Thanks for everyone who did assist and was blocked for SQL injections on the site.
 
What’s worse is that he’s charging people R850 an hour for terrible solutions.

A simple bit of code that addressed the question that was initially asked is a "terrible" solution?

Okay then.

Also, he didn't actually charge for his suggestion. He indicated that he would charge for a (complete) solution (to the apparently constantly unfolding requirements).

Next time try to understand what you're talking about before you slander other people.
 
A simple bit of code that addressed the question that was initially asked is a "terrible" solution?

Okay then.

Also, he didn't actually charge for his suggestion. He indicated that he would charge for a (complete) solution (to the apparently constantly unfolding requirements).

Next time try to understand what you're talking about before you slander other people.

Haha, you obviously didn’t understand my comment.

He didn’t make an effort to extract full requirements, and instead just built a single scenario effort based on his initial interpretation. Also, obviously he’s not charging - who would put up a “solution” on a forum and then ask someone to pay.

All of this provides insight into how he functions, and I can be thankful that I don’t work with someone like that.

Based on your poor interpretation of the scenario and picking up stompies from days ago, you probably ruin solutions together.
 
Haha, you obviously didn’t understand my comment.

Possibly. In my defense, though, I was only responding to what you posted, and not necessarily what you meant to post.

He didn’t make an effort to extract full requirements,

I haven't really seen too many BAs working for free. Have you?

and instead just built a single scenario effort

with the intention of giving the OP an idea as to how OP's (stated) requirements might be met. Also, this particular suggestion is, in fact, a significant improvement over the 2 suggestions immediately preceding it (posts #15 and #16), both of which are single scenario. Could it be that you are perhaps the one that misunderstood the situation?

based on [-]his initial interpretation[/-] the available requirements supplied by the OP.

FTFY. Again, given the 2 preceding suggestions, it is clear that the requirements were understood the same way by each "suggestion provider". Could it be that you are perhaps the one that misunderstood the situation?

Also, obviously he’s not charging - who would put up a “solution” on a forum and then ask someone to pay.

Again, merely responding to what you actually posted, not what you may have meant to post.

All of this provides insight into how he functions,

Supplies ideas for a solution based on a question asked on a forum? Improved significantly on existing suggestions? That sounds like a really helpful guy.

and I can be thankful that I don’t work with someone like that.

Perhaps you're just not the helpful type?

Based on your poor interpretation of the scenario

Again, I can only respond to that which is posted, not that which you meant to post, or that which you think was posted, or that which you wish was posted. Could it be that you are perhaps the one that misunderstood the situation?

and picking up stompies from days ago,

Forgive me, I was not aware that some pertinent communication regarding this thread (all of which I read) took place outside of it. If you can tell me what other information I am missing, I would very much appreciate it.

you probably ruin solutions together.

We'd probably need to work on a solution together in order to ruin it together. Since I don't even have a cooking clue who he is, that scenario is pretty unlikely. (In fact, my apologies if "he" is actually a "she")

At this point, I really have to express concern for your knees: they must be taking quite a lot of strain given all this jumping to conclusions that you are doing.

Also, your posts seem to indicate a preference for slander and/or ad hominem attacks. Is this just generally how you are, or is there a specific reason you chose this approach?
 
Last edited:
I actually generated 50,000,000 random records for this and tested it a few times with and without indices.
The results surprised me a bit.
I thought the sorting in the row_number() one would have a bigger impact on performance than it did, but it was the fastest, on par with envo`s,
my scalar sub-query a second slower.
The last 2 I posted were terrible solutions.
about 2,2,3,14,40 seconds respectively

I`d rate the row_number one as by far the best because you could add as many [types] as you wanted and it would still work.

now i`m done with sql for the week ,lol
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X