Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Databases.. 
Author Message
Doesn't have much of a life
User avatar

Joined: Thu Apr 23, 2009 7:16 pm
Posts: 704
Location: Leeds, UK
Reply with quote
Hey guys,

Wondering if you can help me. My project basically need a way to get a load of data from a massive database and then run a query in SQL to get more data. It's a little complicated so i'll explain:

I've got an SQL query to get a list of host keys. There's 38,000 (students at leeds university!) so doing it manually is a bit of a no-no. I then need to run another query on all 38,000 of those and save each output as a .csv file. Might take an age so that's fine.

I was thinking, would it be possible to use another language (say, Python cos its easy) to open up a list of all the host keys, run an SQL query on each of them and save them? Or even better would it be possible in SQL?


Wed Aug 18, 2010 9:52 am
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 5288
Location: ln -s /London ~
Reply with quote
Why do you have to query the database twice? Surely you query it once, getting all the relevant records, and then you deal with them how you see fit (in this case it seems to be outputting them to a csv file). And yes, for just outputting to a simple text file I'd use something like Python.

_________________
timark_uk wrote:
Gay sex is better than no sex

timark_uk wrote:
Edward Armitage is Awesome. Yes, that's right. Awesome with a A.


Wed Aug 18, 2010 10:07 am
Profile
Doesn't have much of a life
User avatar

Joined: Thu Apr 23, 2009 7:16 pm
Posts: 704
Location: Leeds, UK
Reply with quote
Well the first query would be to get the host keys, the second query would be to use said host keys to bring up that person's timetable. But if there's another way to do it i'm very open to suggestions - i'm an absolute novice at all this! Could there be a way to run one query which would take every host key and put it through the timetable fetching query?


Wed Aug 18, 2010 10:23 am
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 5288
Location: ln -s /London ~
Reply with quote
Angelic wrote:
Well the first query would be to get the host keys, the second query would be to use said host keys to bring up that person's timetable. But if there's another way to do it i'm very open to suggestions - i'm an absolute novice at all this! Could there be a way to run one query which would take every host key and put it through the timetable fetching query?

I'd imagine so, depending on the database structure, but you'd have a query a bit like:

Code:
SELECT [ALL THE FIELDS YOU WANT TO STORE IN THE CSV]
FROM [ALL THE TABLES YOU HAVE TO GRAB STUFF FROM]
WHERE [HOST KEY IS ONE YOU'RE INTERESTED IN] AND [CONDITIONAL STUFF TO GET AT TIMETABLE]


I'd have a looksy at w3schools.com for more ideas of what can be done with SQL.

_________________
timark_uk wrote:
Gay sex is better than no sex

timark_uk wrote:
Edward Armitage is Awesome. Yes, that's right. Awesome with a A.


Wed Aug 18, 2010 10:49 am
Profile
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 4876
Location: Newcastle
Reply with quote
Is it MS SQL server?

If so do it in .Net, then you gain file writing and direct DB interaction and it's a cleaner way to use it than manually running multiple actions by just running one

_________________
Twitter
Charlie Brooker:
Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.


Wed Aug 18, 2010 12:54 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 5288
Location: ln -s /London ~
Reply with quote
finlay666 wrote:
If so do it in .Net, then you gain file writing and direct DB interaction and it's a cleaner way to use it than manually running multiple actions by just running one

Good point, although by the sounds of it this won't take 50 lines of Python, and is only going to be used once or twice, so I'd just clobber it together and be done with it!

_________________
timark_uk wrote:
Gay sex is better than no sex

timark_uk wrote:
Edward Armitage is Awesome. Yes, that's right. Awesome with a A.


Wed Aug 18, 2010 1:16 pm
Profile
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 4876
Location: Newcastle
Reply with quote
with a link to the dbml....

foreach(person s in persons)
{
// pull the host key (if you need to)
..

// create the csv
s.CreateCSV(string.format("Someplace/{0}.csv", s.id);
}

then have a method to create the CSV from the object

bish bash bosh, jobs a good'un

_________________
Twitter
Charlie Brooker:
Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.


Wed Aug 18, 2010 4:40 pm
Profile
Doesn't have much of a life
User avatar

Joined: Thu Apr 23, 2009 7:16 pm
Posts: 704
Location: Leeds, UK
Reply with quote
Hm, I shall definitely be looking into this .net thinger... How hard is it to do something like this from no experience in about a day?


Wed Aug 18, 2010 9:54 pm
Profile WWW
What's a life?
User avatar

Joined: Thu Apr 23, 2009 8:25 pm
Posts: 10691
Location: Bramsche
Reply with quote
Angelic wrote:
Well the first query would be to get the host keys, the second query would be to use said host keys to bring up that person's timetable. But if there's another way to do it i'm very open to suggestions - i'm an absolute novice at all this! Could there be a way to run one query which would take every host key and put it through the timetable fetching query?

Using a sub-select as the WHERE clause should work.

Code:
SELECT fields FROM table WHERE table.field IN (SELECT MastKey FROM MasterTable WHERE CriteriaForStudents);

_________________
"Do you know what this is? Hmm? No, I can see you do not. You have that vacant look in your eyes, which says hold my head to your ear, you will hear the sea!" - Londo Molari

Executive Producer No Agenda Show 246


Thu Aug 19, 2010 4:12 am
Profile ICQ
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 5288
Location: ln -s /London ~
Reply with quote
Angelic wrote:
Hm, I shall definitely be looking into this .net thinger... How hard is it to do something like this from no experience in about a day?

I still reckon it's overkill for something this trivial, and locks you into Windows! Sorry Finlay! (I do want to pick up .Net dev again, it's just kind of pointless for uni coursework as everything has to compile on a unix box) (8-p)

_________________
timark_uk wrote:
Gay sex is better than no sex

timark_uk wrote:
Edward Armitage is Awesome. Yes, that's right. Awesome with a A.


Thu Aug 19, 2010 8:28 am
Profile
Doesn't have much of a life
User avatar

Joined: Thu Apr 23, 2009 7:16 pm
Posts: 704
Location: Leeds, UK
Reply with quote
Okay after looking into .Net...

I think I know LESS about it now than I did when I started.

Python it is!


Thu Aug 19, 2010 10:05 am
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 5288
Location: ln -s /London ~
Reply with quote
[quote="Angelic"]Okay after looking into .Net...quote]
It's definitely worth looking into at some point (assuming you want to do MS development), I just wouldn't bother for this.

_________________
timark_uk wrote:
Gay sex is better than no sex

timark_uk wrote:
Edward Armitage is Awesome. Yes, that's right. Awesome with a A.


Thu Aug 19, 2010 10:17 am
Profile
Doesn't have much of a life
User avatar

Joined: Thu Apr 23, 2009 7:16 pm
Posts: 704
Location: Leeds, UK
Reply with quote
I might at some point recreationally, but it probably won't be to do professionally - i'm just not good enough!

Right this is the query that brings up my own timetable:

GET_TIMETABLE
Code:
Select name,scheduled_periods,duration
from sdowner.SDVC_ACTIVITY
where Id IN
(Select Id from sdowner.SDVR_ALLC_SET
where Student_Set = (select Id from sdowner.SDO_STUDENT_SET
where HOST_KEY ='597050' ))

And this is the query that gets all the host keys:

GET_HOST_KEYS
Code:
select host_key
from sdowner.SDO_STUDENT_SET

To be safe, just to test it works, I can add:

GET_SPECIFIC_HOST_KEYS
Code:
where department = ‘32642DAC5B87808BCCF150497CA14982’

and that will only bring up 200 results (the Computing students).

Is there any way to combine these? It's highly confusing me... Or will this be a case of running the GET_HOST_KEYS query, saving it as a CSV and from within python running a loop to run the GET_TIMETABLE query for each row in the CSV?


Thu Aug 19, 2010 10:22 am
Profile WWW
What's a life?
User avatar

Joined: Thu Apr 23, 2009 8:25 pm
Posts: 10691
Location: Bramsche
Reply with quote
Just replace the specific host key with the department where clause... At least for the second 2.

What is the relation between SDVR_ALLC_SET and SDO_STUDENT_SET?

_________________
"Do you know what this is? Hmm? No, I can see you do not. You have that vacant look in your eyes, which says hold my head to your ear, you will hear the sea!" - Londo Molari

Executive Producer No Agenda Show 246


Thu Aug 19, 2010 11:42 am
Profile ICQ
Doesn't have much of a life
User avatar

Joined: Thu Apr 23, 2009 7:16 pm
Posts: 704
Location: Leeds, UK
Reply with quote
I don't quite understand? Replace what with whonow? Sorry to be so dense!

I'm not sure what the relationship is entirely, but I believe it's something like SDO_STUDENT_SET is where my key is found, and SDVR_ALLC_SET is where the SDO_STUDENT_SET is as they're separated into staff and students...

I could be entirely wrong though. The lovely lady that guided me through it spoke quite a lot of jargon and keeping up with her was a challenge to say the least.


Thu Aug 19, 2010 11:59 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 22 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.