Loading...

Mysql查詢特定欄位相乘總合

Temperature: 0 °C

ChungChung
author_tools

最近常常會用到的查詢方式...

問題是這樣的,有一個資料表內容結構如下:


+----+--------+-----------+----------+
| id   | subject |  people  |  money  |
+----+--------+-----------+----------+
| 10  | 標題1   |      1      |    2000    |
| 12  | 標題1   |      2      |    3000    |
| 13  | 標題2   |      3      |    1000    |
| 20  | 標題2   |      1      |    500      |
| 21  | 標題1   |      2      |    1200    |
+----+--------+-----------+----------+

現在想查詢上面資料表中subject為【標題1】且(people * money)的欄位總合,那麼該怎麼下查詢指令?

可使用方式:

SELECT SUM(people*money) as monsy_s FROM `table` WHERE `subject`='標題1';

所以將會得到以下結果

+-----------+
| money_s |
+-----------+
|   10400   |
+-----------+

 

台北市內湖區江南街71巷75弄 Go

https://innstory.com/story-Mysql查詢特定欄位相乘總合-492
寫程式筆記

Prev
 行程第5天道出悠悠歷史的名城名古屋城

Next
將照片加入簽名檔 

Nearby Attractions

台北市內湖區江南街71巷75弄-Nearby Attractions

  • 義芳居古厝 Go
  • 曹洞宗大本山臺灣別院鐘樓 Go
  • 白榕蔭堂墓園(白崇禧將軍墓)... Go
  • 臺灣總督府博物館 Go
  • 原臺北信用組合(今合作金庫城... Go
  • 骨科醫院及住宅 Go

About the Author

Chung

我是chung
網路工作者
主業是網站系統開發建置
副業是做夢,寫故事
作品請參考/teme.biz
做夢請參考/innstory.com
聯絡/chung.teme@gmail.com

#有人用筆寫日記,有人用歲月寫日記,有人用照片寫日記,而我,用innstory寫日記。

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

Responsive Web Design使用CSS3的Media Queries進行自適應網頁設計

Responsive Web...

智慧型手持裝置(手機、平板)已是非常普及的日常生活必需品。 所以現在,在開發系統時客戶都會詢問是否支...

圖型插件Elastislide

圖型插件Elastislid...

teach Elastislide是一款好用的圖形插件......

php函式紀錄

php函式紀錄

常常忘記,只得紀錄下來...... AddSlashes: 字符串加入斜線。 binhex: 二進位...

Recommended reading

Other stories happened at this address

過了三點一刻,但還是先來杯南洋咖啡吧~

過了三點一刻,但還是先來杯南...

過了三點一刻,但還是先來杯南洋咖啡吧~

很久沒畫了~2015年11月29日這是我第一張嘗試畫在手機裡~

很久沒畫了~2015年11月...

s 小時候~喜歡畫畫,但其實是模仿著家姐的腳步~ 我姐姐以前畫畫很灑脫~隨便幾筆、隨便上色~看起來都...

這笑容是想甜死誰啊~

這笑容是想甜死誰啊~

回到台北幾天了~這幾天常見到他笑。 原本有些小擔心....因為在南部住了一段時間,回到台北後不知道他...

javascript 底下使用 htmlspecialchars

javascript 底下使...

pexelsphoto Javascript中使用一個函數達到PHP的htmlspecialchar...

認真蓋他的城堡,啟動小腦袋思考模式

認真蓋他的城堡,啟動小腦袋思...

認真蓋他的城堡,啟動小腦袋思考模式

鍾式打拋豬佐黑松沙士

鍾式打拋豬佐黑松沙士

只要有機會吃泰國菜,打拋豬一直都是我必點的料理之一。 這幾天熱到要命,需要來點開胃菜。 在冰箱抓了蕃...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format