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

PHP網路爬蟲之抓取Open Graph(OG) Meta tags

PHP網路爬蟲之抓取Open...

用google爬了很多文章.... 最後終於找到一篇內容..... 只是測試了半天...感覺奇怪為何...

利用 css 讓 ul 置中呈現

利用 css 讓 ul 置中...

以前寫網站...總是喜歡用Table 包住內容.. 而隨著時空的轉換...現在大都用div..或者....

修練中

修練中

假日二胡修練中。

Recommended reading

Other stories happened at this address

排列組合年紀~

排列組合年紀~

s 不知不覺的到了開始喜歡上排列組合遊戲的年紀。 總是把玩具或車車拿到某個角落空間。 然後開始堆疊起...

1歲9個月

1歲9個月

歲個月~ 凡事都有第一次,對於這麼小的年紀,一切更是新鮮有趣~但可不包括現在這樣子。 人生第一次長針...

這幾天,有點閒~

這幾天,有點閒~

這幾天有點閒~除了明天得去一趟高雄出差外....好像也沒什麼特別要忙的... 因為說好了,到農曆新年...

聖誕節快樂,恩~我想從現在開始一直到農曆新年結束...應該都保持休假心態吧XD

聖誕節快樂,恩~我想從現在開...

聖誕節快樂,恩~我想從現在開始一直到農曆新年結束...應該都保持休假心態吧XD

數字是不是真的會說話?

數字是不是真的會說話?

以前,在寫下第個網站的那時,我其實非常迷戀數字。 每次看著計數器上數字的跳動,我知道那跳動的不只是數...

手工餅乾

手工餅乾

我曾想像過一個場景..... 一家層樓高的咖啡店,樓下賣的是咖啡、手工餅乾、悠閒還有人情味。 樓賣的...

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