April 10, 2013 at 2:01 pm
I have a table structure as follows:
guidA, market, isInMarket, guidB (lets just say all of these columns are strings)
I would like to get a count grouped by market, where guidA == guidB and isInMarket == 1
for example:
row 1: 23458-293-392-29182, AR, 1, 23458-293-392-29182 <-- want this to add 1 to count
row 2: 19383-958-958-95832, AR, 1, 39201-394-999-84757 <-- this is not a match
output example:
Market, MatchCount
AR, 467
This seems so simple, however, I'm having trouble with it.
April 10, 2013 at 2:08 pm
matthew.knudsen (4/10/2013)
I have a table structure as follows:guidA, market, isInMarket, guidB (lets just say all of these columns are strings)
I would like to get a count grouped by market, where guidA == guidB and isInMarket == 1
for example:
row 1: 23458-293-392-29182, AR, 1, 23458-293-392-29182 <-- want this to add 1 to count
row 2: 19383-958-958-95832, AR, 1, 39201-394-999-84757 <-- this is not a match
output example:
Market, MatchCount
AR, 467
This seems so simple, however, I'm having trouble with it.
Hi and welcome to the forums. There is not much detail to go on here. I took a shot in the dark.
select Market, count(*)
from YourTable
where guidA = guidB
group by Market
If this is not correct you need to post a bit more detail. Please take a few minutes and read the first article linked in my signature for best practices when posting questions.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
April 10, 2013 at 2:08 pm
matthew.knudsen (4/10/2013)
I have a table structure as follows:guidA, market, isInMarket, guidB (lets just say all of these columns are strings)
I would like to get a count grouped by market, where guidA == guidB and isInMarket == 1
for example:
row 1: 23458-293-392-29182, AR, 1, 23458-293-392-29182 <-- want this to add 1 to count
row 2: 19383-958-958-95832, AR, 1, 39201-394-999-84757 <-- this is not a match
output example:
Market, MatchCount
AR, 467
This seems so simple, however, I'm having trouble with it.
Give this a shot.
select
Market,
count(*) as MatchCount
from
dbo.YourTable
where
guidA = guidB and isInMarket = 1
group by
Market;
April 10, 2013 at 2:09 pm
LOL Lynn's code looks almost the same as mine...except he remembered the isInMarket part. 😉
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
April 10, 2013 at 2:13 pm
Thanks for welcoming me to the forums! I think you guys are both correct here. Just completely brain farting over here. This is what happens when you go from C# to C++ to SQL all in the same 10 minutes. eventually I hit reactor overload 🙂
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply