Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 10-29-2005, 06:32 PM   #1
Registered: Feb 2004
Posts: 34

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

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.
Old 10-29-2005, 08:58 PM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

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

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



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 10:52 AM
SQL queries per page (PHP, MySQL) Silent1 Programming 2 06-28-2004 12:15 AM
SQL: making queries from multiple tables ganninu Programming 1 01-08-2004 12:17 PM
JSP: sql queries markus1982 Programming 0 11-05-2003 06:20 AM
sql queries in C program dnewman5 Programming 0 09-14-2001 02:34 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:43 AM.

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