最簡單的解決方案,以編程來說,將是創建一個表委員會4個字段:Id_Commission,Nr_Commission_Min_Value,Nr_Commission_Max_Value,Nr_Commission_Percent
你會再打電話像一個SELECT語句(測試和工作在MySQL中,其TSQL是非常,非常類似於MSACCESS的):下面
SELECT DISTINCT Id_Car, Car.Ds_Car_Description, Car.Nr_Car_Price, Commission.Nr_Commission_Percent * Car.Nr_Car_Price/100 As Commission_Payable FROM Car LEFT JOIN Commission ON (Car.Nr_Car_Price BETWEEN Commission.Nr_Commission_Min_Value AND Commission.Nr_Commission_Max_Value) WHERE Car.Ic_Car_Sold = 1 ORDER BY Car.Nr_Car_Price DESC
,在SQL用於創建和填充這些表。
CREATE TABLE IF NOT EXISTS Commission (
Id_Commision int(11) NOT NULL,
Nr_Commission_Min_Value double NOT NULL,
Nr_Commission_Max_Value double NOT NULL,
Nr_Commission_Percent double NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
INSERT INTO Commission (Id_Commision, Nr_Commission_Min_Value, Nr_Commission_Max_Value, Nr_Commission_Percent) VALUES
(0, 0, 5000, 5),
(1, 5001, 10000, 6),
(2, 10001, 15000, 7),
(3, 15001, 1000000000000, 8);
CREATE TABLE IF NOT EXISTS Car (
Id_Car int(11) NOT NULL AUTO_INCREMENT,
Ds_Car_Description varchar(20) COLLATE utf8_bin NOT NULL,
Nr_Car_Price double NOT NULL,
Ic_Car_Sold tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (Id_Car)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=7 ;
INSERT INTO Car (Id_Car, Ds_Car_Description, Nr_Car_Price, Ic_Car_Sold) VALUES
(1, 'Lotus', 20000, 1),
(2, 'Renault 5', 1000, 1),
(3, 'Audi A3', 6000, 1),
(4, 'Fiat Mille', 300, 1),
(5, 'Land Rover', 12000, 0),
(6, 'Lotus', 25000, 1);
在命名字段,我使用標識爲主要指標,NR數字,Ds的字符串和Ic爲布爾值。我選擇了爲巴西銀行設計數據庫的標準。
請不要爲同一個問題提出一個新問題;只需編輯您的原始問題,並將其標記爲重新打開即可。 – LittleBobbyTables 2013-02-26 15:31:51
我不知道你可以這樣做......我的壞。抱歉。 – KingJohnno 2013-02-26 15:32:40
您的佣金表應該有兩列,一列用於最低價格,另一列用於定義範圍的最高價格。 – 2013-02-26 15:32:57