Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ME55AGE5
Starting Member
2 Posts |
Posted - 2010-02-12 : 10:11:11
|
| I want to create a list of all wells that have 2 or more wellbore_id when values for parent_wellbore_id that are null have been removed, anybody got any suggestionsEXCLUDE row for wellbore_id in list when wb.parent_wellbore_id IS NULL (TABLE1)SELECT LIST of wellbore_id FROM TABLE1 WHERE wellbore_id >= 2Create TABLE with this dataSELECTwb.wellbore_id, we.well_id, wb.parent_wellbore_id, po.policy_id, pr.project_id, si.site_idFROM wb, we, si, pr, poWHERE (((wb.parent_wellbore_id IS NOT NULL))) AND ((we.well_id = wb.well_id) AND (si.site_id = we.site_id) AND (pr.project_id = si.project_id) AND (po.policy_id = pr.policy_id))Had thought about creating a table temp_cd_wellbore_parent_is_not_null and then do a count on wellbore id > 2 but not sure how to do thiscreate table temp_cd_wb_parent_is_not_null as (select * from wb where parent_wellbore_id is not null)Can someone help pleaseTABLESpo--------policy_id--------------------------pr-------policy_idproject_id--------------------------si----project_idsite_id --------------------------we------- site_id well_id--------------------------wb--------well_id wellbore_idparent_wellbore_id |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-12 : 10:23:35
|
do you mean this?SELECT * INTO YourDestTableFROM wbWHERE wellbore_id >= 2AND parent_wellbore_id IS NULL ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
ME55AGE5
Starting Member
2 Posts |
Posted - 2010-02-12 : 10:56:09
|
| A little more info with example of the data in the tablewellbore_id is a unique identifier and I am trying to obtain a count of the amount of times this appears under the associated well_id For examplewell_1 might have 3 wellbore id so this well_id should be storedwell_2 might have 2 wellbore id so this well_id should be storedwell_3 might have 1 wellbore id so this well_id should not be added to tableWould hope to end up with a table that contains a list of the well_id of the wells that have 2 or more wellbore associated to the well_id |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-12 : 11:06:02
|
| [code]SELECT well_id INTO YourDestTableFROM wbWHERE parent_wellbore_id IS NULLGROUP BY well_idHAVING COUNT(DISTINCT wellbore id) > 1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
ms65g
Constraint Violating Yak Guru
497 Posts |
Posted - 2010-02-12 : 13:35:38
|
| [code]SELECT well_id INTO YourDestTable FROM wb WHERE CHECKSUM(parent_wellbore_id) = 2147483647 GROUP BY well_idHAVING MIN(wellbore_id) < MAX(wellbore_id);[/code] |
 |
|
|
|
|
|