DeveloperBarn Forums

Go Back   DeveloperBarn Forums > Databases > SQL Development

Discuss "Query help" in the SQL Development forum.

SQL Development - Structured Query Language (SQL) is the talk of databases. Discuss topics such as joins, triggers and other advanced SQL topics.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old June 6th, 2008, 01:59 PM
mehere's Avatar
Super Mistress of Sarcasm

 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 111
Thanks: 8
Thanked 20 Times in 18 Posts
Rep Power: 1
mehere is on a distinguished road

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

Default Query help

i have a table that has:

pol_num, trn_code, new_pol_num

now what i need to extract is any pol_num that has more than one 'Z' trn_code, but different new_pol_num ... something like this

table data
123 -- Z -- 987
123 -- Z -- 876
456 -- Z -- 654
456 -- Z -- 654

in the above instance ... it would only return pol_num 123 since that has 2 different new_pol_num(s).

any idea.
__________________
Quote of the Month:
Strife: As long as we have each other, we'll never run out of problems.

Questions to Ponder:
Should vegetarians eat animal crackers?

iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
copyright © 2008 sbenj69
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old June 6th, 2008, 02:13 PM
Rebelle's Avatar
Contributing Member

 
Join Date: Mar 2008
Posts: 163
Thanks: 30
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Default

something like this?

SELECT distinct new_pol_num, pol_num, trn_code
FROM Table1
WHERE (((trn_code)="z"))


wait, sorry i think this will give you the opposite...it will give you one 456 because the new_pol is the same.

Last edited by Rebelle; June 6th, 2008 at 02:17 PM.
Reply With Quote
  #3 (permalink)  
Old June 6th, 2008, 02:18 PM
mehere's Avatar
Super Mistress of Sarcasm

 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 111
Thanks: 8
Thanked 20 Times in 18 Posts
Rep Power: 1
mehere is on a distinguished road

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

Default

that's correct rebelle ... not to mention that it get's slightly more complicated as i only want to deal with pol_num that have more than 1 'Z' trn_code.
Reply With Quote
  #4 (permalink)  
Old June 6th, 2008, 02:33 PM
Wolffy's Avatar
Slaprentice of Wolves


 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 146
Thanks: 1
Thanked 23 Times in 20 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

Haven't tested this yet, but you sound desparate
Code:
select pol_num, new_pol_num
 from myTable
where trn_code = 'Z'
 group by pol_num, new_pol_num
 having count(1) > 1
__________________
Wolffy
------------------------
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary.
Reply With Quote
  #5 (permalink)  
Old June 6th, 2008, 02:38 PM
Rebelle's Avatar
Contributing Member

 
Join Date: Mar 2008
Posts: 163
Thanks: 30
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Default

yeah...i think this is about the same or similar to Wolffy's.

Code:
SELECT pol_num, trn_code, Count(new_pol_num) AS Countnew_pol_num
FROM mytable
GROUP BY pol_num, new_pol_num
HAVING (((trn_code)="z") AND ((Count(new_pol_num))>1))

Last edited by Rebelle; June 6th, 2008 at 02:59 PM. Reason: add code tags
Reply With Quote
  #6 (permalink)  
Old June 6th, 2008, 02:43 PM
Wolffy's Avatar
Slaprentice of Wolves


 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 146
Thanks: 1
Thanked 23 Times in 20 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

Close, but it doesn't work. Got it to work in Oralce, but that doesn't help.
Reply With Quote
  #7 (permalink)  
Old June 6th, 2008, 02:47 PM
mehere's Avatar
Super Mistress of Sarcasm

 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 111
Thanks: 8
Thanked 20 Times in 18 Posts
Rep Power: 1
mehere is on a distinguished road

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

Default

how did you get it to work in Oracle? it's driving me nuts
Reply With Quote
  #8 (permalink)  
Old June 6th, 2008, 02:57 PM
Wolffy's Avatar
Slaprentice of Wolves


 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 146
Thanks: 1
Thanked 23 Times in 20 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

Code:
select pol_num from
(select distinct pol_num, new_pol_num from myTable
where trn_code = 'Z') as A
group by pol_num
having count(pol_num) > 1
It was bloody syntax. Oracle didn't require the table alias.
Reply With Quote
The Following User Says Thank You to Wolffy For This Useful Post:
mehere (June 6th, 2008)
  #9 (permalink)  
Old June 6th, 2008, 03:09 PM
sbenj69's Avatar
Moderator

 
Join Date: Mar 2008
Posts: 73
Thanks: 18
Thanked 20 Times in 15 Posts
Rep Power: 1
sbenj69 is on a distinguished road

Awards Showcase
Microsoft Windows Microsoft Access 
Total Awards: 2

Default

SELECT test.pol_num, test.trn_code, Count(test.new_pol_num) AS CountOfnew_pol_num, test.new_pol_num
FROM test
GROUP BY test.pol_num, test.trn_code, test.new_pol_num
HAVING (((test.trn_code)="z") AND ((Count(test.new_pol_num))=1));
Reply With Quote
  #10 (permalink)  
Old June 6th, 2008, 03:15 PM
mehere's Avatar
Super Mistress of Sarcasm

 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 111
Thanks: 8
Thanked 20 Times in 18 Posts
Rep Power: 1
mehere is on a distinguished road

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

Default

you are my own personal hero ... thanks muchly wolffy.

here's what i ended up doing:
Code:
select full_pol, trn_dt, q_full_pol
from dbo.HO_CONV_TRN 
where full_pol in 
	(select full_pol 
	from
		(select distinct Full_Pol, q_full_pol
		from dbo.HO_CONV_TRN 
		where trn_code = 'z') as A
	group by Full_Pol 
	having count(Full_Pol) > 1)
and trn_code = 'Z'
order by full_pol, q_full_pol
Reply With Quote
Reply

  DeveloperBarn Forums > Databases > SQL Development

Bookmarks

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Query Counts Jaykappy Microsoft Access 13 May 14th, 2008 01:39 PM
SQL VBA Query Jaykappy Microsoft Access 12 May 8th, 2008 09:30 AM


Sponsored Links

ASP.NET Resource Index
a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer.

Free Web Directory
Including Chats and Forums Resources, Offer automatic, instant and free directory submissions.
URLZ Web Directory
URLZ Web Directory

Free Web Directory - Add Your Link
The Little Web Directory
Free Web Directory
Pegasus free web directory is a free directory organised by categories.

Web Directory & SEO Services
dirroot web directory


All times are GMT -4. The time now is 10:58 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Copyright © 2008 DeveloperBarn.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46