• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:21
CEST 03:21
KST 10:21
  • 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
Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun4[ASL21] Ro8 Preview Pt1: Inheritors16[ASL21] Ro16 Preview Pt2: All Star10Team Liquid Map Contest #22 - The Finalists19[ASL21] Ro16 Preview Pt1: Fresh Flow9
Community News
2026 GSL Season 1 Qualifiers25Maestros of the Game 2 announced92026 GSL Tour plans announced15Weekly Cups (April 6-12): herO doubles, "Villains" prevail1MaNa leaves Team Liquid25
StarCraft 2
General
Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Team Liquid Map Contest #22 - The Finalists MaNa leaves Team Liquid Maestros of the Game 2 announced
Tourneys
WardiTV Spring Cup 2026 GSL Season 1 Qualifiers Sparkling Tuna Cup - Weekly Open Tournament INu's Battles#14 <BO.9 2Matches> GSL CK: More events planned pending crowdfunding
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
The PondCast: SC2 News & Results Mutation # 523 Firewall Mutation # 522 Flip My Base Mutation # 521 Memorable Boss
Brood War
General
BW General Discussion Leta's ASL S21 Ro.16 review ASL21 General Discussion JaeDong's ASL S21 Ro16 Post-Review [ASL21] Ro8 Preview Pt1: Inheritors
Tourneys
[BSL22] RO16 Group Stage - 02 - 10 May [Megathread] Daily Proleagues [ASL21] Ro8 Day 1 [ASL21] Ro8 Day 2
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers What's the deal with APM & what's its true value Any training maps people recommend?
Other Games
General Games
Stormgate/Frost Giant Megathread Daigo vs Menard Best of 10 Nintendo Switch Thread Dawn of War IV Diablo IV
Dota 2
The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
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
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread European Politico-economics QA Mega-thread Russo-Ukrainian War Thread 3D technology/software discussion Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion McBoner: A hockey love story
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Sexual Health Of Gamers
TrAiDoS
lurker extra damage testi…
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1517 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
PiGosaur Cup
00:00
#79 (TLMC 22 Edition)
PiGStarcraft498
CranKy Ducklings31
davetesta28
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft498
ProTech112
CosmosSc2 43
Temp0 14
StarCraft: Brood War
Britney 12773
GuemChi 3842
Artosis 649
NaDa 28
Dota 2
monkeys_forever668
Super Smash Bros
hungrybox1089
Other Games
summit1g8382
tarik_tv6854
Day[9].tv758
shahzam518
C9.Mang0430
Maynarde108
PPMD20
minikerr4
Organizations
Other Games
gamesdonequick688
BasetradeTV218
Dota 2
PGL Dota 2 - Main Stream157
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 12 non-featured ]
StarCraft 2
• CranKy Ducklings SOOP3
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Other Games
• Day9tv758
Upcoming Events
GSL
8h 9m
Rogue vs Percival
Zoun vs Solar
Replay Cast
22h 39m
GSL
1d 8h
Cure vs TriGGeR
ByuN vs Bunny
KCM Race Survival
1d 8h
Big Gabe
1d 10h
Replay Cast
1d 22h
Replay Cast
2 days
Escore
2 days
OSC
2 days
Replay Cast
2 days
[ Show More ]
Replay Cast
3 days
RSL Revival
3 days
IPSL
3 days
Ret vs Art_Of_Turtle
Radley vs TBD
BSL
3 days
Replay Cast
3 days
RSL Revival
4 days
uThermal 2v2 Circuit
4 days
BSL
4 days
IPSL
4 days
eOnzErG vs TBD
G5 vs Nesh
Replay Cast
5 days
Wardi Open
5 days
Afreeca Starleague
5 days
Jaedong vs Light
Monday Night Weeklies
5 days
Replay Cast
5 days
Sparkling Tuna Cup
6 days
Afreeca Starleague
6 days
Snow vs Flash
Liquipedia Results

Completed

Proleague 2026-04-28
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
StarCraft2 Community Team League 2026 Spring
2026 GSL S1
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026

Upcoming

Escore Tournament S2: W5
KK 2v2 League Season 1
Acropolis #4
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
RSL Revival: Season 5
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
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.