[英]How to count total dates?
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
i am listing user with last inserted date by this query 我通过此查询列出了最后插入日期的用户
SELECT s.username,
(
SELECT br1.requireddate
from bloodrequest as br1
where br1.bloodrequest_id =
(
select max(br2.bloodrequest_id)
from bloodrequest as br2
where br2.seeker_nic = s.seeker_nic
)
) as requireddate
FROM seeker as s
this query works proper and show me data like this. 此查询工作正常,并向我显示这样的数据。
s.no---- username----- requireddate
1------- ali---------- 2012/09/09
2------- umer--------- 2012/7/9
3------- raza--------- 2012/4/4
now i also want one more fild to show the total no of dates for a specific user .. like this 现在我还想要一个fild来显示特定用户的日期总数。
s.no---- username----- requireddate-----total dates
1------- ali---------- 2012/09/09-------4
2------- umer--------- 2012/7/9---------2
3------- raza--------- 2012/4/4---------1
anyone please tell me how to adjust count in this query.. i shall be thankfull..... plzz need help 任何人都请告诉我如何调整此查询中的计数..我将非常感激..... plzz需要帮助
Does the following work? 请问以下工作吗? Please give a try: 请尝试:
SELECT s.username,
(
SELECT br1.requireddate
from bloodrequest as br1
where br1.bloodrequest_id =
(
select max(br2.bloodrequest_id)
from bloodrequest as br2
where br2.seeker_nic = s.seeker_nic
)
) as requireddate,
(
SELECT count(br3.id)
from bloodrequest as br3
where br3.seeker_nic = s.seeker_nic
) as total_dates
FROM seeker as s
Though, it may not be the most efficient one. 虽然,它可能不是最有效的一种。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.