HighTechTalks DotNet Forums  

Query help

Dotnet Framework (ADO.net) microsoft.public.dotnet.framework.adonet


Discuss Query help in the Dotnet Framework (ADO.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Joe
 
Posts: n/a

Default Query help - 09-04-2007 , 09:32 AM






I don't think this is really the right place to post this question but I
couldn't find any sql groups...

Say there are 3 columns:
idx (key)
product (varchar)
mandate (datetime)


I want to run a query for all products that were sold on more than one day.
For example we may not make a product more than one day and some we might
make for 3 days although a product may have been made more then 1 time in a
day.

Here's a sample:

1 widgetA 1/1/2007
2 widgetB 1/1/2007
3 widgetA 1/1/2007
4 widgetC 1/2/2007
5 widgetD 1/3/2007
6 widgetD 1/3/2007
7 widgetB 1/5/2007
8 widgetD 1/6/2007


So I would want the query to return widgetB and widgetD because they were
both made on more then 1 day.

-Joe



Reply With Quote
  #2  
Old   
Petar Atanasov
 
Posts: n/a

Default Re: Query help - 09-04-2007 , 10:52 AM






Joe wrote:
Quote:
I don't think this is really the right place to post this question but I
couldn't find any sql groups...

Say there are 3 columns:
idx (key)
product (varchar)
mandate (datetime)


I want to run a query for all products that were sold on more than one day.
For example we may not make a product more than one day and some we might
make for 3 days although a product may have been made more then 1 time in a
day.

Here's a sample:

1 widgetA 1/1/2007
2 widgetB 1/1/2007
3 widgetA 1/1/2007
4 widgetC 1/2/2007
5 widgetD 1/3/2007
6 widgetD 1/3/2007
7 widgetB 1/5/2007
8 widgetD 1/6/2007


So I would want the query to return widgetB and widgetD because they were
both made on more then 1 day.

-Joe


SELECT COUNT (dat.idx) as idx
, dat.mandate
, MAX(dat.product) as product
FROM dbo.my_data dat
GROUP BY dat.mandate
HAVING COUNT (dat.idx) > 1

HTH,
Petar Atanasov
http://a-wake.net


Reply With Quote
  #3  
Old   
Joe
 
Posts: n/a

Default Re: Query help - 09-04-2007 , 11:39 AM



Hi Petar, This doesn't seem to give me what I want. It looks like the date
is being grouped correctly.

When I run this against ~3200 rows I only get 4 returned although I can
manually see that many, many more should match.

Any idea?

Thanks for the help.
Joe

"Petar Atanasov" <ppa_info (AT) mail (DOT) bg> wrote

Quote:
Joe wrote:
I don't think this is really the right place to post this question but I
couldn't find any sql groups...

Say there are 3 columns:
idx (key)
product (varchar)
mandate (datetime)


I want to run a query for all products that were sold on more than one
day. For example we may not make a product more than one day and some we
might make for 3 days although a product may have been made more then 1
time in a day.

Here's a sample:

1 widgetA 1/1/2007
2 widgetB 1/1/2007
3 widgetA 1/1/2007
4 widgetC 1/2/2007
5 widgetD 1/3/2007
6 widgetD 1/3/2007
7 widgetB 1/5/2007
8 widgetD 1/6/2007


So I would want the query to return widgetB and widgetD because they were
both made on more then 1 day.

-Joe

SELECT COUNT (dat.idx) as idx
, dat.mandate
, MAX(dat.product) as product
FROM dbo.my_data dat
GROUP BY dat.mandate
HAVING COUNT (dat.idx) > 1

HTH,
Petar Atanasov
http://a-wake.net



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.