我想获取创建记录的最新日期(CreatedDate),UserId以及表格中唯一身份用户的总数。
这是我到目前为止所做的,似乎没有用。
Select UserId, MAX(CreatedDate), Count(Distinct UserID) AS 'Number of Users'
From DPP_Exports__Customers
有人可以帮忙吗?
谢谢,
伊克巴尔
答案 0 :(得分:1)
查询最新记录的UserId:
select userid,CreatedDate
from DPP_Exports__Customers
order by CreatedDate desc limit 1;
查询每个用户的最长日期:
select userid,max(CreatedDate)
from DPP_Exports__Customers
group by userid;
查询不同的用户数:
select count(distinct userid) from DPP_Exports__Customers
所有人的单一查询:
select cust.userid,max(cust.CreatedDate) as max_createdDate,
(select count(distinct userid) from DPP_Exports__Customers) as distinct_user_count,
(select userid from DPP_Exports__Customers order by CreatedDate desc limit 1) as latest_userid
from DPP_Exports__Customers cust
group by cust.userid;
答案 1 :(得分:0)
Try it...
Select GROUP_CONCAT(UserId), MAX(CreatedDate), Count(Distinct UserID)AS 'Number of Users',Max(UserId) as latest_user From DPP_Exports__Customers