dscqrkvr9562034621 2012-04-11 19:16
浏览 38

too long

I have two tables, and I want to get the last enterd date.

The first table is seeker:

seeker_nic-----username
111-------------ali
222-------------umer
333-------------raza

The second one is requestblood:

id-------seeker_nic-----requireddate
1-------  111 ----------2012/10/9
2 ------- 222-----------2012/5/8
3 ------  111-----------2012/12/12
4 ------- 111-----------2012/11/12
5---------111-----------2012/09/09
6 ------- 222-----------2012/7/9
7 ------- 333 ----------2012/4/4

Now, I want to list the users one time with their last inserted date like..

s.no---- username----- requireddate
 1------- ali---------- 2012/09/09
 2------- umer--------- 2012/7/9
 3------- raza--------- 2012/4/4

I am using this query, but it shows maximum date not the latest one.

SELECT seeker.username, MAX(bloodrequest.requireddate) AS requireddate, COUNT(bloodrequest.requireddate) AS total
FROM seeker
JOIN bloodrequest
  ON seeker.seeker_nic = bloodrequest.seeker_nic
GROUP BY seeker.username

This shows the maximum date, and it shows total dates. For example, 111 has total "4", but I don't know how to show the last inserted date... I am new in PHP, please help me. :(

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dsfsfsfsfs55656 2012-04-11 21:39
    关注

    Very simple but you will need to use subselect - acquire row with last id (this will work only if you have correct indexing - i suppose you have).

    Example:

    SELECT seeker_nic, username, 
    (SELECT `requiredate` FROM `requestblood` WHERE `seeker_nic`=`seeker`.`seeker_nic` ORDER BY `id` DESC LIMIT 1) as `last_requiredate`
    FROM `seeker`
    
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题