0

我正在开发一个网站,第一种形式有两个表单 searchscreen 和 serachresultscreen 我从两个下拉列表中选择一个范围(即从 value1 到 value 2)

范围是为了钻石净度,分别按顺序

FL,IF,VVS,VVS1,VVS2,SI,SI1,I1,I2

当我在下一个表单上查询它时

clarity>=FL and clarity<=VVS1

然后它显示字母 F 到 V 之间的所有值的结果(即FL,IF,VVS,VVS1,VV2,SI,I1,I2

请给我一些答案

我需要的输出是(当在 from=FL to=VVS1 之间选择时)然后FL,IF,VVS,VVS1只输出结果值

4

1 回答 1

1

您不能BETWEEN对字符串值使用范围运算符。要解决此问题,请为这些钻石净度值创建具有相应数字权重的表。

在基于 Clarity 进行过滤时,获取其订单,然后将所有这些 ORDER(数字)放入 Range Operator

编辑 :

CREATE TABLE DIAMOND_CLARITY
(CLARITY VARCHAR(10),
 CLARITY_ORDER int
)

INSERT INTO DIAMOND_CLARITY values ('FL',1)
INSERT INTO DIAMOND_CLARITY values ('IF',2)
INSERT INTO DIAMOND_CLARITY values ('VVS',3)
INSERT INTO DIAMOND_CLARITY values ('VVS1',4)
INSERT INTO DIAMOND_CLARITY values ('VVS2',5)
INSERT INTO DIAMOND_CLARITY values ('SI',6)
INSERT INTO DIAMOND_CLARITY values ('SI1',7)
INSERT INTO DIAMOND_CLARITY values ('I1',8)
INSERT INTO DIAMOND_CLARITY values ('I2',9)

查询以获取范围之间的记录

    SELECT CLARITY from DIAMOND_CLARITY where CLARITY_ORDER 
BETWEEN
    (SELECT CLARITY_ORDER FROM DIAMOND_CLARITY where CLARITY='FL')
    AND 
    (SELECT CLARITY_ORDER FROM DIAMOND_CLARITY where CLARITY='VVS')
于 2013-05-25T06:16:52.340 回答