• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 03:41
CEST 09:41
KST 16:41
  • 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
Serral wins HomeStory Cup 2914Serral wins Maestros of the Game 243ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12
Community News
Balance hotfix patch 5.0.16b (July 16)43Reynor: GSL Loss Wasn't About Preparation Format16[IPSL] Spring 2026 Grand Finals - This Weekend!5Weekly Cups (July 6 - 12): Protoss strike back12BSL Season 22 Full Overview & Conclusion8
StarCraft 2
General
Balance hotfix patch 5.0.16b (July 16) [D] Wireframe Casting Removed Clem: "I don't have that much hope in Blizzard" Reynor: GSL Loss Wasn't About Preparation Format Is the larve respawn broken?
Tourneys
Master Swan Open (Global Bronze-Master 2) WardiTV Summer Cup 2026 GSL CK #5 Race War RSL Revival: Season 6 - Qualifiers and Main Event HomeStory Cup 29
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
The PondCast: SC2 News & Results Mutation # 534 Burning Evacuation Mutation # 533 Die Together Mutation # 532 Nuclear Family
Brood War
General
BW General Discussion Pros Debate: Zerg Unfairly Nerfed? (ASL S22 map) Etiquete rules in Asl? Recent recommended BW games Recommended FPV games (post-KeSPA)
Tourneys
Escore Tournament - Season 3 [Megathread] Daily Proleagues Small VOD Thread 2.0 [IPSL] Spring 2026 Grand Finals - This Weekend!
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Creating a full chart of Zerg builds Relatively freeroll strategies
Other Games
General Games
General RTS Discussion Thread Path of Exile Nintendo Switch Thread Beyond All Reason Stormgate/Frost Giant Megathread
Dota 2
Looking for a Dota Mentor 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
TL Mafia
TL Mafia Power Rank NeO.D_StephenKing vs This Guy From 1 Million Dance TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread The Games Industry And ATVI Russo-Ukrainian War Thread UK Politics Mega-thread YouTube Thread
Fan Clubs
The IdrA Fan Club The HerO Fan Club!
Media & Entertainment
Movie Discussion! Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books Series you have seen recently...
Sports
2024 - 2026 Football Thread MLB/Baseball 2023 McBoner: A hockey love story Tennis[sport] Formula 1 Discussion
World Cup 2022
Tech Support
Simple Questions Simple Answers FPS when play League Of Legend on laptop How to clean a TTe Thermaltake keyboard?
TL Community
Northern Ireland Global Starcraft The Automated Ban List
Blogs
Poker (part 2)
Nebuchad
The Experiences We Want and …
TrAiDoS
An Exploration of th…
waywardstrategy
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Evil Gacha Games and the…
ffswowsucks
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 7614 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 19m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft722
SortOf 191
StarCraft: Brood War
Shuttle 2122
Leta 279
Larva 188
Dewaltoss 111
Dota 2
Fuzer 70
League of Legends
JimRising 667
Other Games
summit1g6786
XaKoH 146
amsayoshi79
Organizations
Other Games
gamesdonequick2228
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 13 non-featured ]
StarCraft 2
• Berry_CruncH315
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota2306
League of Legends
• Stunt621
Upcoming Events
RSL Revival
1h 19m
Clem vs Lambo
Scarlett vs Cure
CranKy Ducklings
2h 19m
Epic.LAN
5h 19m
IPSL
8h 19m
Dragon vs Hawk
RSL Revival
1d 1h
Classic vs Trap
herO vs SHIN
Sparkling Tuna Cup
1d 2h
OSC
1d 5h
IPSL
1d 8h
Bonyth vs Ret
WardiTV Weekly
2 days
Monday Night Weeklies
2 days
[ Show More ]
PiGosaur Cup
3 days
The PondCast
4 days
Replay Cast
5 days
CrankTV Team League
5 days
Replay Cast
5 days
CrankTV Team League
6 days
Korean StarCraft League
6 days
Liquipedia Results

Completed

Escore Tournament S3: W3
HSC XXIX
Eternal Conflict S2 E2

Ongoing

IPSL Spring 2026
Acropolis #4
YSL S3
CSL 2026 Summer (S21)
KCM Race Survival 2026 Season 3
ASL S22 SEASON OPEN Day 1
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
SCTL 2026 Spring
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026

Upcoming

Escore Tournament S3: W4
ASL S22 SEASON OPEN Day 2
Escore Tournament S3: W5
CSLAN 4
Blizzard Classic Cup 2026
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
Light Tournament 2026
Eternal Conflict S2 Finale
Eternal Conflict S2 E3
Logitech G Connect 2026
StarSeries Fall 2026
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
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 © 2026 TLnet. All Rights Reserved.