2 Replies - 650 Views - Last Post: 27 May 2010 - 05:28 PM Rate Topic: -----

#1 d_rop4nme  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 17
  • View blog
  • Posts: 149
  • Joined: 18-April 10

SQL QUERY question

Posted 25 May 2010 - 12:52 PM

Hi,

I'm a newbie programmer, especially with SQL ... I have an idea for a SQL query I just wanted to see if I am approaching this the right way to see if it is even possible before I devote a load of time to tackling it ...

I have an exported .csv file with about 200,000 records that I need to re-import into my database, however, first I need to sort (either manually or preferably with a SQL statement ... )

Right Now I have multiple dates, start to end, for the same MatterNo (key) I need to reduce this to the earliest start date and the latest end date for each MatterNo (see example below), should probably cut it in half, so I can properly import ...

The criteria would be that where the same MatterNo appears more then once if the entries are the same delete multiples, if the MatterNo has multiple Date of Service START take the lowest date of service and the Highest Date of Service END and put them with one MatterNo ( I think this could be done with multiple statements ? )

I know how to do basic UPDATE, QUERY, DELETE statements but this a lil beyond my scope at the moment, If this is possible to do if someone could point me in the right direction would be greatly appreciated.

Ex ...
MatterNo	DOS Start	DOS End
LCJ08-31661	11/3/2008	11/3/2008
LCJ07-18293	4/30/2004	5/3/2004
09-10399	4/10/2009	4/13/2009
LCJ07-18293	5/5/2004	5/7/2004
LCJ08-31661	11/3/2008	11/3/2008
LCJ08-31661	11/3/2008	11/3/2008
LCJ07-18293	5/12/2004	5/12/2004
LCJ07-18293	5/14/2004	5/17/2004
LCJ08-31662	11/3/2008	11/3/2008
09-11107	8/17/2009	8/17/2009



Any guidance would be greatly appreciated on this

Is This A Good Question/Topic? 0
  • +

Replies To: SQL QUERY question

#2 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5641
  • View blog
  • Posts: 12,359
  • Joined: 16-October 07

Re: SQL QUERY question

Posted 25 May 2010 - 01:05 PM

Unless I'm missing something, it simply sounds like this:

SELECT "MatterNo", 
		MIN("DOS Start") as "DOS Start",
		MAX("DOS End") as "DOS End"
	FROM Table
	GROUP BY "MatterNo"


Was This Post Helpful? 1
  • +
  • -

#3 d_rop4nme  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 17
  • View blog
  • Posts: 149
  • Joined: 18-April 10

Re: SQL QUERY question

Posted 27 May 2010 - 05:28 PM

Thanks very much I had to adapt it a lil bit to but you definatley put me on the right track
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1