MySQL查询帮助 [英] Mysql Query Help

查看:101
本文介绍了MySQL查询帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写以下问题的查询??

考虑具有以下结构的称为carrecords的表:
名称(类型:TEXT)
价格(类型:INT)
颜色(类型:TEXT)
车辆类型(类型:TEXT),例如轿车/SUV

客户希望查看适合其偏好的车辆的详细信息(名称,价格,颜色,车辆类型).他是这样说的:
如果是黑色轿车,我准备支付10,000,但如果是红色或白色,则不超过8,000.对于其他任何颜色,除非是SUV,否则我的价格不会超过7,000.如果我的预算是黑色的最高预算为15,000,其他颜色的最高预算为14,000."

编写一个查询,以价格升序返回所需的信息.

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.

推荐答案

只是因为您删除了并在周一之前将其交出"并没有掩盖事实这是你的功课.

你尝试了什么?您遇到什么问题?
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?


我正在尝试

I m trying

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)
)


您需要首先学习如何在SQL中编写查询.请参考一些书,然后尝试.
You need to study first about How to write Query in SQL. Refer some book and then try.


这篇关于MySQL查询帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆