dongshuobei1037 2013-08-10 05:26
浏览 30
已采纳

基于两个表的MYSQL计数

Sorry for asking this, but I haven't found an answer to what I'm trying to do anywhere!

Basically, I have a database with two tables. Below or two examples I'll use:

Table 1:

Process ID  Date
---------- -----------
         1  2008/08/21
         2  2008/08/23
         3  2008/08/21

Table 2:

Process ID Qty
---------- ---
         1   1
         2   4
         3   6

Basically, I was to do something in PHP where I will select table 1, and find all processes that occur today (in this example I'll say the 21st of August). I then want to take those process ids, and match them in Table two and give a count of their quantities.

The end result I'm trying to figure out in this example is how do I get the output to be "7" by using PHP to select the processes that happened today in one table, then add up the corresponding process quantities in another table.

  • 写回答

1条回答 默认 最新

  • doufengsui7449 2013-08-10 05:29
    关注
    SELECT sum(t2.qty)
    FROM table1 t1
    JOIN table2 t2 ON t1.pid = t2.pid
    WHERE t1.date = '2008/08/21'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎么获取下面的: glove_word2id.json和 glove_numpy.npy 这两个文件
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug