douran9707 2013-04-17 05:31
浏览 30

计算一个表中两到三天之间的天数

I have a table named transaction_detail which contains id_transd, id_trans, id_cust and inputtime.

  id_transd | id_trans | id_cust | inputtime           |
  1         | 1        | 1       | 2013-04-15 16:55:58 | 
  2         | 1        | 1       | 2013-05-15 16:55:58 | 
  3         | 1        | 1       | 2013-06-15 16:55:58 |
  4         | 2        | 2       | 2013-06-15 16:55:58 | 
  ...

I want to get the amount of the inputtime which have the same id_cust and id_trans.
For example : when admin wants to count how long the job done on one costumer then admin need to click on the name of the customer and system will calculate the date.

 |No.| Name     | Process     | Time                |
 |1. | D-net    | by sales    | 2013-04-15 16:55:58 |
 |   |          | by sadmin   | 2013-05-15 16:55:58 |
 |   |          | by technic  | 2013-06-15 16:55:58 |

I've tried this code

SELECT t.* datediff(DAY, t.inputtime, nextdate) AS Days_Between
FROM
  (SELECT t.*,
    (SELECT min(inputtime)
      FROM transaksi_detail t2
      WHERE t.id_cust = t2.id_cust
        AND t.id_trans = t2.id_trans
        AND t.inputtime < t2.inputtime) AS nextdate
   FROM transaction_detail t)t

But won't work, It says :

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in F:\htdocs\indosat2\hitung_tanggal2.php on line 20
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)