• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 05:14
CET 11:14
KST 19:14
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband Information Request Regarding Chinese Ladder
Tourneys
$5,000+ WardiTV 2025 Championship Constellation Cup - Main Event - Stellar Fest RSL Revival: Season 3 Tenacious Turtle Tussle [Alpha Pro Series] Nice vs Cure
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
Data analysis on 70 million replays Which season is the best in ASL? [ASL20] Ask the mapmakers — Drop your questions BW General Discussion FlaSh's Valkyrie Copium
Tourneys
[Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET [BSL21] RO16 Group C - Saturday 21:00 CET Small VOD Thread 2.0
Strategy
Game Theory for Starcraft How to stay on top of macro? Current Meta PvZ map balance
Other Games
General Games
Stormgate/Frost Giant Megathread The Perfect Game Path of Exile Nintendo Switch Thread Should offensive tower rushing be viable in RTS games?
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine US Politics Mega-thread The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
James Bond movies ranking - pa…
Topin
Esports Earnings: Bigger Pri…
TrAiDoS
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 907 users

The Big Programming Thread - Page 423

Forum Index > General Forum
Post a Reply
Prev 1 421 422 423 424 425 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2014-01-08 14:27:05
January 08 2014 14:19 GMT
#8441
On January 08 2014 21:51 nunez wrote:
Show nested quote +
On January 08 2014 20:05 darkness wrote:
On January 08 2014 09:50 nunez wrote:
On January 08 2014 07:55 darkness wrote:
On January 08 2014 04:36 Arnstein wrote:
CTRL+C does the trick I just wanted to look at how/if the number would go to 3.5 if I would take the average of X dice rolls, and then I could just CTRL+C when I wanted to stop.


Then
while (true)
may be better to write instead. It's more readable than
while (1)


Or even better:


bool loopShouldContinue = true;
while (loopShouldContinue) {
// do your work
// when you're finished
loopShouldContinue = false;
// or you could write
break;
// but then that may make the point of the boolean variable irrelevant
// it just depends on what you want to do exactly
}


Don't forget to import

#include <stdbool.h>

if you use the boolean approach.

#############################

I've got a question. When you don't need a class instance to do something (e.g. to get an unsorted array and return a sorted one), is it advisable to make that method static in general?


loopShouldContinue clearly does express the intention of the programmer precisely enough, it's even less expressive than while(1)!

try:
while(sinceThisProgramIsJustForMyOwnExperimentationThisLoopWillJustRunUntilITerminatedAtMyDiscretinonWithCtrlC)


Don't be so grumpy. The name of the boolean variable can be easily renamed, and it was just an example. You're just acting like an ass at the moment with your sarcasm.

your post was well-intentioned, but misguided and misplaced nitpicking, borderline overbearing... it persists!


Well, it's hard to give a proper name for a boolean that is used for while condition if you're unclear about context. E.g. boolean stringFound when searching for a string. Yes, "isDone" / "done" may be better than "loopShouldContinue" but it's still as generic. You just nitpicked about the variable's name, while it was just an example, hence the guy is supposed to rename it.

And yes, I use higher level languages (Java and Objective-C) which may explain why I prefer
while (true)
rather than
while (1)
nunez
Profile Blog Joined February 2011
Norway4003 Posts
January 08 2014 14:29 GMT
#8442
On January 08 2014 23:19 darkness wrote:
Show nested quote +
On January 08 2014 21:51 nunez wrote:
On January 08 2014 20:05 darkness wrote:
On January 08 2014 09:50 nunez wrote:
On January 08 2014 07:55 darkness wrote:
On January 08 2014 04:36 Arnstein wrote:
CTRL+C does the trick I just wanted to look at how/if the number would go to 3.5 if I would take the average of X dice rolls, and then I could just CTRL+C when I wanted to stop.


Then
while (true)
may be better to write instead. It's more readable than
while (1)


Or even better:


bool loopShouldContinue = true;
while (loopShouldContinue) {
// do your work
// when you're finished
loopShouldContinue = false;
// or you could write
break;
// but then that may make the point of the boolean variable irrelevant
// it just depends on what you want to do exactly
}


Don't forget to import

#include <stdbool.h>

if you use the boolean approach.

#############################

I've got a question. When you don't need a class instance to do something (e.g. to get an unsorted array and return a sorted one), is it advisable to make that method static in general?


loopShouldContinue clearly does express the intention of the programmer precisely enough, it's even less expressive than while(1)!

try:
while(sinceThisProgramIsJustForMyOwnExperimentationThisLoopWillJustRunUntilITerminatedAtMyDiscretinonWithCtrlC)


Don't be so grumpy. The name of the boolean variable can be easily renamed, and it was just an example. You're just acting like an ass at the moment with your sarcasm.

your post was well-intentioned, but misguided and misplaced nitpicking, borderline overbearing... it persists!


Well, it's hard to give a proper name for a boolean that is used for while condition if you're unclear about context. E.g. boolean stringFound when searching for a string. Yes, "isDone" / "done" may be better than "loopShouldContinue" but it's still as generic. You just nitpicked about the variable's name, while it was just an example, hence the guy is supposed to rename it.

And yes, I use higher level languages (Java and Objective-C) which may explain why I prefer
while (true)
rather than
while (1)


haha, yes, i am aware of the irony. ;>
conspired against by a confederacy of dunces.
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
January 08 2014 16:15 GMT
#8443
On January 08 2014 07:55 darkness wrote:
Show nested quote +
On January 08 2014 04:36 Arnstein wrote:
CTRL+C does the trick I just wanted to look at how/if the number would go to 3.5 if I would take the average of X dice rolls, and then I could just CTRL+C when I wanted to stop.


Then
while (true)
may be better to write instead. It's more readable than
while (1)


Or even better:


bool loopShouldContinue = true;
while (loopShouldContinue) {
// do your work
// when you're finished
loopShouldContinue = false;
// or you could write
break;
// but then that may make the point of the boolean variable irrelevant
// it just depends on what you want to do exactly
}


Don't forget to import

#include <stdbool.h>

if you use the boolean approach.

#############################

I've got a question. When you don't need a class instance to do something (e.g. to get an unsorted array and return a sorted one), is it advisable to make that method static in general?


Thanks for the suggestion. I suppose i's always important to consider different approaches. However, in this case, when I was just experimenting on my own, I do not think it is necessary to do all that stuff. All I wanted to do in the end, was to check how the average of many dice rolls would end up being around 3,5. What I learnt from this, is that you should use %d to printf ints, and %f to printf floats, so by just doing that stupid thing, I actually learnt something! I love it when my curiosity ends up teaching me something 8)
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
Zocat
Profile Joined April 2010
Germany2229 Posts
Last Edited: 2014-01-08 16:40:49
January 08 2014 16:38 GMT
#8444
On January 09 2014 01:15 Arnstein wrote:
All I wanted to do in the end, was to check how the average of many dice rolls would end up being around 3,5.


And your program doesn't do that. Dice rolls can be simulated by a PRNG. Your program doesn't generate PRNG numbers.
Why?
Your srand(time(NULL)) is inside the while loop, which means every time you initialize the PRNG with a specific seed. Since you execute the while loop multiple times per second (unless you use a potato) the seed is identical. Which means rand() returns the same value for every execution in a second.
You should invoke srand exactly once outside your while loop.
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
Last Edited: 2014-01-08 20:29:04
January 08 2014 17:01 GMT
#8445
I know the thing I posted here doesn't even divide by the number of throws. I just had to figure out how to print ints and floats before doing the rest. I have a background from C++, and it's the same srand function, but I forgot that it should be outside until the first time it printed the sum when aI realized it :p I can post the complete code if you are interested, but I'm not at the computer at the moment.

Edit:
Here it is:

+ Show Spoiler +

#include <stdio.h>
#include <time.h>


int main()
{
unsigned long int sum = 0;
unsigned int n = 1;
double average;
srand(time(NULL));
while ( 1 )
{
sum += rand() % 6 + 1;
average = (double)sum / (double)n;
n += 1;
if ( (n % 1000000) == 0 )
printf("The average is:%f\n", average);

}
return 0;
}
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
unkkz
Profile Blog Joined December 2007
Norway2196 Posts
Last Edited: 2014-01-09 10:59:15
January 09 2014 10:35 GMT
#8446
Was hoping someone in here could help me with an SQL query, it's an MS 2008 R2 client.

The following is that i have a table with receipts, there are columns for how big the bank sale of of each receipt was. I need a query that pretty much goes "where x + x = y" the following simple try returns some issues:

where subtotal + subtotal = '100,50' and created >= '2014-01-01'

This can return the same receipt twice, aka taking the same receipt x 2 = y. I need to ensure that it takes two separate ones and try to match them to the Y value, something i cannot figure out how to do despite decent google skills. Anyone that can help me out? I assume i have to assign something to each subtotal colum in the query so that it is something like where subtotal(x) + subtotal(z) (WHERE subtotal(x) <> subtotal(z)) = y but i am very clueless about the syntax.
Roman666
Profile Joined April 2012
Poland1440 Posts
January 09 2014 11:24 GMT
#8447
On January 09 2014 19:35 unkkz wrote:
Was hoping someone in here could help me with an SQL query, it's an MS 2008 R2 client.

The following is that i have a table with receipts, there are columns for how big the bank sale of of each receipt was. I need a query that pretty much goes "where x + x = y" the following simple try returns some issues:

where subtotal + subtotal = '100,50' and created >= '2014-01-01'

This can return the same receipt twice, aka taking the same receipt x 2 = y. I need to ensure that it takes two separate ones and try to match them to the Y value, something i cannot figure out how to do despite decent google skills. Anyone that can help me out? I assume i have to assign something to each subtotal colum in the query so that it is something like where subtotal(x) + subtotal(z) (WHERE subtotal(x) <> subtotal(z)) = y but i am very clueless about the syntax.

Well without knowing the table structure or the query as a whole, it will be hard to help and even understand this problem. I read it several times and still can not understand what is exactly the issue here.

You mention that you are getting duplicated values, but this would be only possible if you would join the table with another table. Perhaps there are receipts with the same values.

Seeing you mention something like subtotals, I take it there is a GROUP BY in the query, or a window calculation. But not seeing the query itself (or at least the conditions and GROUP BY clause) it will be hard to help you out.
berated-
Profile Blog Joined February 2007
United States1134 Posts
Last Edited: 2014-01-09 11:26:57
January 09 2014 11:24 GMT
#8448
On January 09 2014 19:35 unkkz wrote:
Was hoping someone in here could help me with an SQL query, it's an MS 2008 R2 client.

The following is that i have a table with receipts, there are columns for how big the bank sale of of each receipt was. I need a query that pretty much goes "where x + x = y" the following simple try returns some issues:

where subtotal + subtotal = '100,50' and created >= '2014-01-01'

This can return the same receipt twice, aka taking the same receipt x 2 = y. I need to ensure that it takes two separate ones and try to match them to the Y value, something i cannot figure out how to do despite decent google skills. Anyone that can help me out? I assume i have to assign something to each subtotal colum in the query so that it is something like where subtotal(x) + subtotal(z) (WHERE subtotal(x) <> subtotal(z)) = y but i am very clueless about the syntax.


is there any reason you are going so generic with your description? it makes it hard to help...

are you joining back on your own table or using two different columns from the same table for your columns? posting your table and query so far would make this a ton easier.

with that being said if you are joining to yourself and you have some id column just add and id1 != id2 to your where clause... if you are using multiple columns add col1 != col2

edit: too slow ... shouldn't have used my tablet or I could have been first
unkkz
Profile Blog Joined December 2007
Norway2196 Posts
Last Edited: 2014-01-09 12:05:32
January 09 2014 11:48 GMT
#8449
On January 09 2014 20:24 Roman666 wrote:
Show nested quote +
On January 09 2014 19:35 unkkz wrote:
Was hoping someone in here could help me with an SQL query, it's an MS 2008 R2 client.

The following is that i have a table with receipts, there are columns for how big the bank sale of of each receipt was. I need a query that pretty much goes "where x + x = y" the following simple try returns some issues:

where subtotal + subtotal = '100,50' and created >= '2014-01-01'

This can return the same receipt twice, aka taking the same receipt x 2 = y. I need to ensure that it takes two separate ones and try to match them to the Y value, something i cannot figure out how to do despite decent google skills. Anyone that can help me out? I assume i have to assign something to each subtotal colum in the query so that it is something like where subtotal(x) + subtotal(z) (WHERE subtotal(x) <> subtotal(z)) = y but i am very clueless about the syntax.

Well without knowing the table structure or the query as a whole, it will be hard to help and even understand this problem. I read it several times and still can not understand what is exactly the issue here.

You mention that you are getting duplicated values, but this would be only possible if you would join the table with another table. Perhaps there are receipts with the same values.

Seeing you mention something like subtotals, I take it there is a GROUP BY in the query, or a window calculation. But not seeing the query itself (or at least the conditions and GROUP BY clause) it will be hard to help you out.


That is my query, there isn't anything else, i think you overestimate me a little bit heh i'm being so generic because i am not good at SQL and i notice that i forgot to mention that subtotal was a column, which is why you guys are even more confused i bet, sorry about that. I mention duplicate values because running the simple where subtotal + subtotal = '100' and created >= '2014-01-01' gives me one single hit that has half the value i am looking for, aka it takes subtotal x2.

The issue is that i need to find two separate values from the column "subtotal" that equals another value that i want to find. I am looking for say 220 and want to find all possible combinations that equals 220 if u add them together from the column subtotal. I actually have something to differentiate them by, another column named receiptid which is unique per entry in the table. I am also doing this query just straight into the table itself which i dont know if its the proper way or not.
artynko
Profile Joined November 2010
Slovakia86 Posts
January 09 2014 11:59 GMT
#8450
On January 09 2014 19:35 unkkz wrote:
Was hoping someone in here could help me with an SQL query, it's an MS 2008 R2 client.

The following is that i have a table with receipts, there are columns for how big the bank sale of of each receipt was. I need a query that pretty much goes "where x + x = y" the following simple try returns some issues:

where subtotal + subtotal = '100,50' and created >= '2014-01-01'

This can return the same receipt twice, aka taking the same receipt x 2 = y. I need to ensure that it takes two separate ones and try to match them to the Y value, something i cannot figure out how to do despite decent google skills. Anyone that can help me out? I assume i have to assign something to each subtotal colum in the query so that it is something like where subtotal(x) + subtotal(z) (WHERE subtotal(x) <> subtotal(z)) = y but i am very clueless about the syntax.


I assume you have an inner join there and what you are doing is t1.subtotal + t2.subtotal where t1, t2 are both the same table from inner join, the only thing you need is to add t1.id != t2.id and it won't compare sums of the same record
unkkz
Profile Blog Joined December 2007
Norway2196 Posts
January 09 2014 12:09 GMT
#8451
On January 09 2014 20:59 artynko wrote:
Show nested quote +
On January 09 2014 19:35 unkkz wrote:
Was hoping someone in here could help me with an SQL query, it's an MS 2008 R2 client.

The following is that i have a table with receipts, there are columns for how big the bank sale of of each receipt was. I need a query that pretty much goes "where x + x = y" the following simple try returns some issues:

where subtotal + subtotal = '100,50' and created >= '2014-01-01'

This can return the same receipt twice, aka taking the same receipt x 2 = y. I need to ensure that it takes two separate ones and try to match them to the Y value, something i cannot figure out how to do despite decent google skills. Anyone that can help me out? I assume i have to assign something to each subtotal colum in the query so that it is something like where subtotal(x) + subtotal(z) (WHERE subtotal(x) <> subtotal(z)) = y but i am very clueless about the syntax.


I assume you have an inner join there and what you are doing is t1.subtotal + t2.subtotal where t1, t2 are both the same table from inner join, the only thing you need is to add t1.id != t2.id and it won't compare sums of the same record


Mind giving me an example? Pretty SQL noob here
artynko
Profile Joined November 2010
Slovakia86 Posts
January 09 2014 12:12 GMT
#8452
select * from t1, t2 where t1.id != t2.id - and it is not an inner join, for some reason I blanked and called it incorrectly
Roman666
Profile Joined April 2012
Poland1440 Posts
January 09 2014 12:42 GMT
#8453
On January 09 2014 21:09 unkkz wrote:
Show nested quote +
On January 09 2014 20:59 artynko wrote:
On January 09 2014 19:35 unkkz wrote:
Was hoping someone in here could help me with an SQL query, it's an MS 2008 R2 client.

The following is that i have a table with receipts, there are columns for how big the bank sale of of each receipt was. I need a query that pretty much goes "where x + x = y" the following simple try returns some issues:

where subtotal + subtotal = '100,50' and created >= '2014-01-01'

This can return the same receipt twice, aka taking the same receipt x 2 = y. I need to ensure that it takes two separate ones and try to match them to the Y value, something i cannot figure out how to do despite decent google skills. Anyone that can help me out? I assume i have to assign something to each subtotal colum in the query so that it is something like where subtotal(x) + subtotal(z) (WHERE subtotal(x) <> subtotal(z)) = y but i am very clueless about the syntax.


I assume you have an inner join there and what you are doing is t1.subtotal + t2.subtotal where t1, t2 are both the same table from inner join, the only thing you need is to add t1.id != t2.id and it won't compare sums of the same record


Mind giving me an example? Pretty SQL noob here

So basically you want to find subsets of receipts which values sum up to a given value. Well, this is not a straight forward query, but it is doable.

If you can confirm that this is exactly what you want I can show you how to write such query, however I can do it later in the afternoon as I have to go out now and writing this query and explanations for it is not something that will take 5 minutes. Also I will need to check out availability of certain query mechanisms on MS SQL, but I think this will be possible to be done.
unkkz
Profile Blog Joined December 2007
Norway2196 Posts
January 09 2014 12:59 GMT
#8454
On January 09 2014 21:42 Roman666 wrote:
Show nested quote +
On January 09 2014 21:09 unkkz wrote:
On January 09 2014 20:59 artynko wrote:
On January 09 2014 19:35 unkkz wrote:
Was hoping someone in here could help me with an SQL query, it's an MS 2008 R2 client.

The following is that i have a table with receipts, there are columns for how big the bank sale of of each receipt was. I need a query that pretty much goes "where x + x = y" the following simple try returns some issues:

where subtotal + subtotal = '100,50' and created >= '2014-01-01'

This can return the same receipt twice, aka taking the same receipt x 2 = y. I need to ensure that it takes two separate ones and try to match them to the Y value, something i cannot figure out how to do despite decent google skills. Anyone that can help me out? I assume i have to assign something to each subtotal colum in the query so that it is something like where subtotal(x) + subtotal(z) (WHERE subtotal(x) <> subtotal(z)) = y but i am very clueless about the syntax.


I assume you have an inner join there and what you are doing is t1.subtotal + t2.subtotal where t1, t2 are both the same table from inner join, the only thing you need is to add t1.id != t2.id and it won't compare sums of the same record


Mind giving me an example? Pretty SQL noob here

So basically you want to find subsets of receipts which values sum up to a given value. Well, this is not a straight forward query, but it is doable.

If you can confirm that this is exactly what you want I can show you how to write such query, however I can do it later in the afternoon as I have to go out now and writing this query and explanations for it is not something that will take 5 minutes. Also I will need to check out availability of certain query mechanisms on MS SQL, but I think this will be possible to be done.


Yeah that would be it. Wouldn't something like
select * from dbo.poslog where subtotal.id1 + subtotal.id2 = '553,90' and subtotal.id1 != subtotal.id2
except with proper syntax work? Trying to figure out how to get id's on columns. I can't alter stuff since this is a prod server.
Roman666
Profile Joined April 2012
Poland1440 Posts
Last Edited: 2014-01-09 15:09:46
January 09 2014 15:04 GMT
#8455
On January 09 2014 21:59 unkkz wrote:
Show nested quote +
On January 09 2014 21:42 Roman666 wrote:
On January 09 2014 21:09 unkkz wrote:
On January 09 2014 20:59 artynko wrote:
On January 09 2014 19:35 unkkz wrote:
Was hoping someone in here could help me with an SQL query, it's an MS 2008 R2 client.

The following is that i have a table with receipts, there are columns for how big the bank sale of of each receipt was. I need a query that pretty much goes "where x + x = y" the following simple try returns some issues:

where subtotal + subtotal = '100,50' and created >= '2014-01-01'

This can return the same receipt twice, aka taking the same receipt x 2 = y. I need to ensure that it takes two separate ones and try to match them to the Y value, something i cannot figure out how to do despite decent google skills. Anyone that can help me out? I assume i have to assign something to each subtotal colum in the query so that it is something like where subtotal(x) + subtotal(z) (WHERE subtotal(x) <> subtotal(z)) = y but i am very clueless about the syntax.


I assume you have an inner join there and what you are doing is t1.subtotal + t2.subtotal where t1, t2 are both the same table from inner join, the only thing you need is to add t1.id != t2.id and it won't compare sums of the same record


Mind giving me an example? Pretty SQL noob here

So basically you want to find subsets of receipts which values sum up to a given value. Well, this is not a straight forward query, but it is doable.

If you can confirm that this is exactly what you want I can show you how to write such query, however I can do it later in the afternoon as I have to go out now and writing this query and explanations for it is not something that will take 5 minutes. Also I will need to check out availability of certain query mechanisms on MS SQL, but I think this will be possible to be done.


Yeah that would be it. Wouldn't something like
select * from dbo.poslog where subtotal.id1 + subtotal.id2 = '553,90' and subtotal.id1 != subtotal.id2
except with proper syntax work? Trying to figure out how to get id's on columns. I can't alter stuff since this is a prod server.


select t1.*, t2.* from dbo.poslog t1 inner join dbo.poslog t2 on t1.subtotal + t2.subtotal = 553,90 and t1.receiptid != t2.receiptid;

That would be the proper syntax. However, you want that only to work for pairs of receipts? It will identify paired receipts, but this way, you will not be able to find, say three receipts which sum of subtotals would equal to 553,90.
artynko
Profile Joined November 2010
Slovakia86 Posts
January 09 2014 16:17 GMT
#8456
Then you will also run into the problem where you have duplicates where one id is in first column and second in second and a duplicate where it is inverted, but that is another mystery to solve
enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
Last Edited: 2014-01-09 17:33:38
January 09 2014 17:24 GMT
#8457
Try using a cross join. Cross joins will take two sets of rows and generate every possible combination between them.

SELECT *
FROM dbo.poslog t1
CROSS JOIN dbo.poslog t2
WHERE t1.receiptid != t2.receiptid
AND t1.subtotal + t2.subtotal = 553,90


If you want three or more possible combinations, you can union them

SELECT t1.receiptid as Receipt1, t2.receiptid as Receipt2, -1 as Receipt3
FROM dbo.poslog t1
CROSS JOIN dbo.poslog t2
WHERE t1.receiptid != t2.receiptid
AND t1.subtotal + t2.subtotal = 553,90

UNION

SELECT t1.receiptid as Receipt1, t2.receiptid as Receipt2, t3.receiptid as Receipt3
FROM dbo.poslog t1
CROSS JOIN dbo.poslog t2
CROSS JOIN dbo.poslog t3
WHERE t1.receiptid != t2.receiptid AND t1.receiptid != t3.receiptid AND t2.receiptid != t3.receiptid
AND t1.subtotal + t2.subtotal + t3.subtotal = 553,90

...

If you need more than three, or the ability to choose how many combinations on demand, you can use temp tables or dynamic sql.
Roman666
Profile Joined April 2012
Poland1440 Posts
Last Edited: 2014-01-09 17:42:52
January 09 2014 17:40 GMT
#8458
On January 10 2014 01:17 artynko wrote:
Then you will also run into the problem where you have duplicates where one id is in first column and second in second and a duplicate where it is inverted, but that is another mystery to solve


Right, it will pop each pair twice with interchanged positions. The simplest way to fix it that comes to my mind would be:


with pairs as
(
select
t1.receiptid id1,
t2.receiptid id2
from
dbo.poslog t1
inner join
dbo.poslog t2
on
t1.subtotal + t2.subtotal = 553,90
and t1.receiptid != t2.receiptid
),
distinct_pairs as
(
select
t1.id1,
t1.id2
from
pairs t1
inner join
pairs t2
on
t1.id1 = t2.id2
and t1.id2 = t2.id1
and t1.id1 > t1.id2
)
select
t2.*,
t3.*
from
distinct_pairs t1
inner join
dbo.poslog t2
on
t1.id1 = t2.receiptid
inner join
dbo.poslog t3
on
t1.id2 = t3.receiptid;


Google up the WITH clause if you want to find more about it, it is well documented. Basically here I used it as a simple subquery, but it can be used in other ways.

First we find the pairs, we select only ids, as these will uniquely identify our records. (pairs query)
Then we know there will be duplicates, so we take only these, where id1 > id2. We know that id1 and id2 will never be equal as we excluded such pairs in the beginning and we take only one side.
Finally when we have set of distinct pairs, we join up one poslog table with one of the ids, and second poslog table with second of the ids.

EDIT: Edited in relevant quote.
artynko
Profile Joined November 2010
Slovakia86 Posts
Last Edited: 2014-01-09 18:16:06
January 09 2014 18:12 GMT
#8459
hups sorry, just skimmed through the previous answer, posted a condescending answer

EDIT: As far as I know the easiest way if you only want a sum of TWO records and it will always be combination of TWO is "select * from t1, t2 where t1.id != t2.id and t1.id < t2.id and t1.value + t2.value > 9000"
Roman666
Profile Joined April 2012
Poland1440 Posts
January 09 2014 18:34 GMT
#8460
On January 10 2014 03:12 artynko wrote:
hups sorry, just skimmed through the previous answer, posted a condescending answer

EDIT: As far as I know the easiest way if you only want a sum of TWO records and it will always be combination of TWO is "select * from t1, t2 where t1.id != t2.id and t1.id < t2.id and t1.value + t2.value > 9000"


Well, apart from the fact that you do not need t1.id != t2.id when you use t1.id < t2.id you are absolutely right. I have no idea why I overcomplicated it so much. Bleh...
Prev 1 421 422 423 424 425 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 1h 46m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SortOf 222
ProTech122
StarCraft: Brood War
Calm 1429
Horang2 1239
Shuttle 1204
actioN 580
Larva 504
Mini 302
Jaedong 282
Hyun 212
Light 167
Rush 138
[ Show more ]
Sharp 122
Pusan 115
Zeus 112
Killer 101
ZerO 100
Dewaltoss 75
sorry 57
ToSsGirL 43
Last 29
soO 28
NotJumperer 17
Mong 16
ajuk12(nOOB) 11
Hm[arnc] 8
Terrorterran 3
Dota 2
XaKoH 407
XcaliburYe156
League of Legends
JimRising 399
C9.Mang0240
Counter-Strike
olofmeister1313
shoxiejesuss622
Super Smash Bros
Westballz23
Other Games
summit1g10802
Fuzer 113
KnowMe57
ZerO(Twitch)6
Organizations
Other Games
gamesdonequick666
StarCraft: Brood War
UltimateBattle 57
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Berry_CruncH242
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota258
League of Legends
• Jankos1666
• Stunt1083
Upcoming Events
Wardi Open
1h 46m
StarCraft2.fi
6h 46m
Replay Cast
13h 46m
The PondCast
23h 46m
OSC
1d 5h
Demi vs Mixu
Nicoract vs TBD
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
Replay Cast
1d 13h
Korean StarCraft League
2 days
CranKy Ducklings
2 days
SC Evo League
3 days
BSL 21
3 days
Sziky vs OyAji
Gypsy vs eOnzErG
[ Show More ]
OSC
3 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
3 days
OSC
4 days
BSL 21
4 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
4 days
Wardi Open
5 days
StarCraft2.fi
5 days
Replay Cast
5 days
StarCraft2.fi
6 days
PiGosaur Monday
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.