In digital computer programming, a bitwise operation operates on one or more bit patterns or binary numerals at the level of their individual bits. It is a fast, simple action directly supported by the processor, and is used to manipulate values for comparisons and calculations. On simple low-cost processors, typically, bitwise operations are substantially faster than division, several times faster than multiplication, and sometimes significantly faster than addition. While modern processors usually perform addition and multiplication just as fast as bitwise operations due to their longer instruction pipelines and other architectural design choices, bitwise operations do commonly use less power because of the reduced use of resources. bash
CREATE TABLE price
(
id INT PRIMARY KEY,
ap INT DEFAULT NULL,
bp INT DEFAULT NULL,
cp INT DEFAULT NULL,
p INT DEFAULT NULL
);
INSERT INTO price VALUES
(1,NULL,100,93,6),
(2,188,170,203,7),
(3,NULL,14,NULL,2);
INSERT INTO price VALUES
(4,NULL,NULL,NULL,NULL),
(5,44,55,66,7),
(6,NULL,NULL,430,4);
SELECT
id '產品編號',
CASE WHEN p&ap>0 THEN ap
WHEN p&bp>0 THEN bp
WHEN p&cp>0 THEN cp
ELSE '該產品無有效報價'
END '有效報價',
CASE WHEN p&ap>0 THEN 'ap'
WHEN p&bp>0 THEN 'bp'
WHEN p&cp>0 THEN 'cp'
ELSE '無'
END '報價主管'
FROM price;
複製代碼