我正在運行A-B測試以查看哪種風格的頁面可能獲得更多產品訂單,並試圖將一個頁面稱爲比其他頁面「更好」,因爲它更頻繁地顯示。MYSQL中的乘法,除法和加法
我在我的MYSQL數據庫中有8列。
- Orders_Page_One
- Orders_Page_Two
- Orders_Page_Three
- Visitors_Page_One
- Visitors_Page_Two
- Visitors_Page_Three
- Total_Orders
- Total_Visitors
目前我只運行一個查詢爲:
$result = mysql_query("SELECT *, (Total_Orders/Total_Visitors) AS order_percent FROM orders WHERE category = clothes ORDER BY order_percent DESC LIMIT 5") or die(mysql_error());
這工作,但
這讓我顯示哪些訂單是最流行的,但沒有考慮到他們出現的頁面上。
我曾嘗試:
$result = mysql_query("SELECT *, (Orders_Page_One/Visitors_Page_One) + (Orders_Page_Two/Visitors_Page_Two) + (Orders_Page_Three/Visitors_Page_Three) AS order_percent FROM orders WHERE category = clothes ORDER BY order_percent DESC LIMIT 5") or die(mysql_error());
但這似乎並沒有給予準確的結果。
我也試過
$result = mysql_query("SELECT *, ((Orders_Page_One/Visitors_Page_One) + (Orders_Page_Two/Visitors_Page_Two) + (Orders_Page_Three/Visitors_Page_Three)) AS order_percent FROM orders WHERE category = clothes ORDER BY order_percent DESC LIMIT 5") or die(mysql_error());
但是,這給出了一個語法錯誤。
假設:
Orders Page One = 10 and Visitors Page One = 20
Orders Page Two = 10 and Visitors Page Two = 40
Orders Page Three = 10 and Visitors Page Three = 50
的數學結果我想應該是:
(10/20) + (10/40) + (10/50)
OR
0.5 + 0.25 + 0.20 = 0.95
有什麼建議?我想我只是沒有正確設置數學。
經過閱讀中,我想我會需要使用多個選擇:
IE:
Select (orders_page_1/visitors_page_1) as order_percent_1 from orders
Select (orders_page_2/visitors_page_2) as order_percent_2 from orders
Select (orders_page_3/visitors_page_3) as order_percent_3 from orders
Select (order_percent_1 + order_percent_two + order_percent_3) as order_percent
WHERE category = clothes
ORDER BY order_percent DESC
,但不知道在格式化?或者如果這可行?
$result = mysql_query("
SELECT * FROM orders, (
SELECT (orders_page_1/visitors_page_one) AS ord1 FROM orders WHERE category = 'clothing' ORDER BY ord1 DESC LIMIT 2) AS ord_1,
(
SELECT (orders_page_2/visitors_page_two) AS ord2 FROM orders WHERE category = 'clothing' ORDER BY ord2 DESC LIMIT 2) AS ord_2,
(
SELECT (orders_page_3/visitors_page_3) AS ord3 FROM orders WHERE category = 'clothing' ORDER BY ord3 DESC LIMIT 2) AS ord_3,
ORDER BY (ord_1 +ord_2 + ord_3) DESC LIMIT 2") or die(mysql_error());
然而,這是給錯誤:
您的SQL語法錯誤;檢查對應於你的MySQL服務器版本的在線使用近 'ORDER BY(ord_1 + ord_2 + ord_3)DESC LIMIT 2' 正確的語法手冊8
你可以爲它創建一個SQL小提琴嗎? –
我不熟悉SQL小提琴 – user3083472
規範化任何人嗎?我們是否僅限於與你熟悉的事物一起工作? !?!? ;-) – Strawberry