![](/img/trans.png)
[英]How to select two different values from a table with different conditions in mysql?
[英]How to select two elements from two different table
我想計算兩個表中兩個元素的值。 例如,我有兩張桌子,
表A:(item_id,item_price,item_description)
表B:(item_id,item_count,item_color)
我想計算,例如:
item_price * item_count
表示item_id from A = item_id from B
所有item_id from A = item_id from B
。
我該怎么做?
嘗試這個
SELECT a.Item_Id AS Item, a.Item_Price * b.Item_Count AS Tot_Cost
FROM TableA a, TableB b
WHERE a.Item_Id = b.Item_Id;
Equi加入:
SQL EQUI JOIN對相關表執行JOIN或匹配相關表的列值。 等號(=)用作where子句中的比較運算符以引用相等性。
您還可以使用JOIN關鍵字后跟ON關鍵字執行EQUI JOIN,然后指定列的名稱及其關聯表以檢查相等性。
句法:
SELECT column_list
FROM table1, table2....
WHERE table1.column_name =
table2.column_name;
要么
SELECT *
FROM table1
JOIN table2
[ON (join_condition)]
進一步了解如下鏈接。
無論是指定你的病情where
:
SELECT A.item_id, A.item_price * B.item_count AS calculated
FROM A, B
WHERE A.item_id = B.item_id
或者更清楚的是join
:
SELECT A.item_id, A.item_price * B.item_count AS calculated
FROM A
JOIN B ON A.item_id = B.item_id
select a.item_price *b.item_count AS Value from A a,B b where a.item_id=b.item_id
用戶equi加入
select a.item_price *b.item_count AS 'Total Amount' from A a,B b where a.item_id=b.item_id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.