Click here to Skip to main content
15,917,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to write Query for following problom???

Consider a table called carrecords with the following structure:
name (type: TEXT)
price (type: INT)
color (type: TEXT)
vehicletype (type: TEXT) eg. SEDAN/SUV

A customer wants to see the details (name, price, color, vehicletype) of the vehicles that suit his preferences. This is what he says:
"If its a black sedan, I'm ready to pay 10,000, but if its red or white, then no more than 8,000. For any other color I won't go above 7,000, except if its an SUV, in which case my budget is upto 15,000 for a black one or upto 14,000 for any other color."

Write a query that returns the desired information in ascending order of price.
Posted

Just because you removed "and hand it in by Monday" doesn't hide the fact that this is your homework.

What have you tried? What problem are you getting?
 
Share this answer
 
I m trying

SQL
SELECT * FROM carrecords
WHERE
IF(vehicletype= 'SEDAN',
  IF(color='BLACK' AND price <= 10000 ,TRUE,
     IF(color='RED' OR color='WHITE',
       IF(price<=8000, TRUE,FALSE)
     ,
       IF(price<=7000, TRUE,FALSE)
     )
  )
,
  IF(vehicletype = 'SUV',
     IF(color='BLACK',
       IF(price<=15000,TRUE,FALSE)
       ,
       IF(price<='14000',TRUE,FALSE)),FALSE)
)
 
Share this answer
 
You need to study first about How to write Query in SQL. Refer some book and then try.
 
Share this answer
 
Above Query is working in Mysql
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900