• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 19:53
CET 00:53
KST 08:53
  • 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
[ASL22] Finals Preview: Sweet Victory!12[ASL22] Ro4 Preview: Mirror Mirror6[ASL22] Ro8 Preview: Within Reach5[ASL22] Ro8 Preview: In A Tizzy11[ASL22] Ro16 Preview: Holy Diver5
Community News
Weekly Cups (October 19-25): Clem triples first in 5.0.174Evil Geniuses - shutting down20ISSL (IntoTheTV x SOOP SC2 League): Premier5Weekly Cups (October 12-18): 5.0.17 era begins1[$1250] International ShieldBattery League92
StarCraft 2
General
No more SC2 streamers on team liquid? How do you feel about the mass reverts in the 5.0.17 PTR? Weekly Cups (October 19-25): Clem triples first in 5.0.17 Evil Geniuses - shutting down REPORT: StarCraft 2: Remastered In Development
Tourneys
Stellar Fest TWO the Moon (Dec 16-20) RSL 2026 Offline Finals LCQ Sign-Ups Sparkling Tuna Cup - Weekly Open Tournament 2026 KungFu Cup Announcement RSL goes to London! 2026 Offline Finals Nov 21-22
Strategy
[H] ZvP Mid-Late Game: Stalkers Collossi HT
Custom Maps
Simple Questions/Answers [G] How to playtest arcade maps [A] Nemrods 1/4 players
External Content
Mutation # 549 Endless Sparkles The PondCast: SC2 News & Results Mutation # 548 Shining Bright Mutation # 547 Temple Of Terror
Brood War
General
Rollback Netcode in Brood War SC4ALL II Brood War Complete Invited Player Lineup Sagi.gg Launcher Released BW General Discussion Starcraft player cRuZa Passed away.
Tourneys
[IPSL] IPSL Winter 26-27 Ro24 is HERE! [Megathread] Daily Proleagues KCM Race Survival 2026 Season 4 [BSL23] RO24 Group D - Sunday 21:00 CET
Strategy
50,000-Word Terran Builds Memo 2026-10-22 Cliff Jump Revisited (1 in a 1000 strategy) Simple Questions, Simple Answers
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Mobile Legends: Bang Bang Armies of Exigo - YesYes? General RTS Discussion Thread
Dota 2
Dota 2 Champions League Season 3 Begins April 25!
League of Legends
[TL LoL EUW IHs] Teemo shall perish
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine R I P Patrick Stewart European Politico-economics QA Mega-thread
Fan Clubs
Reynor Fan Club The Flash Fan Club Serral Fan Club
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Recent Gifted Posts
Blogs
Innovate or Game Over?
TrAiDoS
ShieldBattery on Mac
Kraekkling
[ASL22] Ro4 Day1 Ticket Giv…
bITt.mAN
Can Bots Beat Pros?? Starcr…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 9108 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 12h 7m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ViBE144
CosmosSc2 19
StarCraft: Brood War
GuemChi 1090
Artosis 603
Rain 377
ProTech161
White-Ra 126
Sexy 55
ajuk12(nOOB) 9
Dota 2
syndereN537
monkeys_forever271
NeuroSwarm141
League of Legends
JimRising 620
Other Games
summit1g8666
Coldzera 745
shahzam588
XaKoH 372
C9.Mang0205
[ Show 15 non-featured ]
StarCraft 2
• Hupsaiya 103
• RyuSc2 39
• EnkiAlexander 25
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis2696
• Jankos2437
• Scarra1172
Other Games
• imaqtpie523
Upcoming Events
GSL
12h 7m
Epic.LAN
13h 7m
Big Brain Bouts
17h 7m
OSC
22h 7m
Replay Cast
23h 7m
Sparkling Tuna Cup
1d 10h
WardiTV Invitational
1d 12h
Epic.LAN
1d 13h
IPSL
1d 16h
eOnzErG vs McRibbed
LancerX vs StRyKeR
AI Arena Tournament
1d 18h
[ Show More ]
OSC
2 days
Yamato Cup
2 days
IPSL
2 days
Artosis vs RiceHat
Kyrie vs Sony
Map Test Tournament
2 days
WardiTV Weekly
3 days
Ultimate Battle
3 days
Rush vs BeSt
Replay Cast
3 days
Rogue vs Classic
Patches Events
4 days
PiGosaur Cup
5 days
Kung Fu Cup
5 days
The PondCast
6 days
KCM Race Survival
6 days
Liquipedia Results

Completed

Proleague 2026-10-28
Blizzard Classic Cup 2026
HCC Season 3

Ongoing

Acropolis #5
KCM Race Survival 2026 Season 4
International ShieldBattery League
BSL Season 23
PGL Masters Bucharest 2026
Stake Ranked Episode 5
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026

Upcoming

IPSL Winter 2026-27
SC4ALL II: Brood War
BSL 23: Non-Korean Championship
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
eXTREMESLAND 2026
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 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.