LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-29-2005, 05:32 PM   #1
cold
Member
 
Registered: Feb 2004
Posts: 34

Rep: Reputation: 15
SQL: tables and queries in school project


Hello,
I'm a SQL beginner and I have a problem with design of tables and SQL queries for my school project so that they are effective. I need to design tables and SQL queries for simple car rental company. The problem is that I have a car and the car is rented for different prices according to month. Let's say:

* 100 per week in January
* 110 per week in Feruary
* etc. etc.

One can rent a car at least for a week but can rent a car for more weeks. The problem I cannot solve in some good way is how to count price of a car in the situation when car is rented for more weeks in different month where prices for week differ. Let's have an exmaple: client want to rent a car from 15.1. till 7.2., so this are two weeks in January and one week in February. The final price would be 100 + 100 + 110 = 310 (don't count weeks in this example; the point is that I have same dates and I need to get the information about prices in between these dates).
The simple algorithm is to get a price for every week and to add these prices then. But this leads to as many SQL queries as weeks I handle. Is it possible to do it in some better way? Can I design the tables and SQL queries in that way that I can get the price in one query?
PS: I use mysql 4.1 but I thnik postgresql is also installed on our school machine (but IAC I don't know the version of it).

Thanks in advance.
Joseph.
 
Old 10-29-2005, 07:58 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Not knowing how the tables are actually laid out you could
(in meta-sql) do something like:

Code:
select sum(price) 
  from price-map 
  where date between 15.1.2005 and 7.2.2005

Cheers,
Tink
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
seaching by SQL queries jonaskoelker LQ Suggestions & Feedback 6 05-27-2005 09:52 AM
SQL queries per page (PHP, MySQL) Silent1 Programming 2 06-27-2004 11:15 PM
SQL: making queries from multiple tables ganninu Programming 1 01-08-2004 11:17 AM
JSP: sql queries markus1982 Programming 0 11-05-2003 05:20 AM
sql queries in C program dnewman5 Programming 0 09-14-2001 01:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration