每討論@ mwan的答案,考慮使用INT
是字段而不是FLOAT
。當您連續行INSERT
時,您可以乘以10的某個冪(取決於您需要的精度水平),並且當您SELECT
時,您可以用相同的冪數除以10,但由於字段爲INT
,您可以始終相信你的WHERE
子句將匹配正確的行:
CREATE TABLE `tbl_products` (
frequency INT,
gain INT,
gain_variation_x100 INT, # give it a name that will remind you
noise INT,
power INT
);
INSERT INTO `tbl_products` VALUES
('1', '2', '0.2' * 100, '2', '10'),
('2', '2', '0.2' * 100, '2', '10'),
('2', '2', '0.5' * 100, '2', '10')
# ↑
# `---- multiply here
;
SELECT *, ROUND(gain_variation_x100/100, 1) AS gain_variation
FROM tbl_products # ^---. ^---- show 1 digit of precision
WHERE frequency BETWEEN '2' AND '3' # \
AND gain = '2' # `----- divide here
AND gain_variation_x100 = ROUND('0.2' * 100)
AND noise = '2' # ^----- multiply here
AND power = '10'
;
你可以看到這個在這裏工作:http://sqlize.com/829275n1Fc
什麼口味SQL的? –
@pekka我正在使用MySQL – Nitish
你的表是否有滿足你的整個'WHERE'子句的行?請向我們展示您期待的行。 –