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

關掉phpinfo()

關掉phpinfo()

pexelsphotod 配置php環境的時候往往都會寫 phpinfo(); 這個函數來測試php...

RewriteRule仿靜態連結

RewriteRule仿靜態...

前幾天寫了關於頁面導向位置的定義。https://innst...

清除網頁暫存(no cache)

清除網頁暫存(no cach...

pexelsphoto5 在製作專案時,有沒有試過JS 或 CSS 明明就已經更新了~ 但頁面卻像鬼...

Recommended reading

Other stories happened at this address

禦寒聖物,有了他,管他寒流來不來~

禦寒聖物,有了他,管他寒流來...

禦寒聖物,有了他,管他寒流來不來~

淡紅色小藥丸

淡紅色小藥丸

s Drug Name Diclofenac mg tab 從沒想過,所謂的坐骨神經痛會發生在自己身...

2018月亮節快樂!!

2018月亮節快樂!!

前些日子Wen哥分享了月份他去北極圈健行的紀錄 雖然說月份的北極圈是永晝的季節~ 但我仍想像著在寬廣...

5U回南部的第一天

5U回南部的第一天

U回南部的第一天..... 非常的不捨但因為G即將到來,怕屆時沒有辦法兼顧,只好麻煩爸媽上來先接回U...

若不抬頭你永遠都不知道樹上有甚麼

若不抬頭你永遠都不知道樹上有...

s 給U~ 若不抬頭,你永遠都不知道樹上有甚麼。 若不爬上樹,你永遠都不知道樹頂有多精彩。

麻油雞泡飯

麻油雞泡飯

再一次,又到了麻油雞酒的季節。 is sesame oil chicken season again...

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