SQL查询获取上次访问日期

时间:2018-09-21 09:45:02

标签: sql ms-access

我有两个桌子

客户

enter image description here

宠物

enter image description here

以下内容可能是sql查询(Msaccess):

输出应该类似这样: enter image description here

3 个答案:

答案 0 :(得分:0)

执行conflicting types for 'pthread_t'并将JOINGROUP BYCOUNT()一起使用:

MAX()

但是,在MS Access中,concat是:

SELECT CONCAT(c.Cus_FName, ' ' c.Cus_LName), COUNT(p.Pet_ID), MAX(p.Pet_LastVisit)
FROM Customer c INNER JOIN
     Pet p
     ON p.Cus_num  = c.Cus_num 
GROUP BY CONCAT(c.Cus_FName, ' ' c.Cus_LName);

答案 1 :(得分:0)

使用联接和聚合

    select c.cus_num,c.cus_Lname,count(p.pet_id) as numberofpets,
   max(p.Pet_LastVisit) as last_visit
     customer c join pet p
    on c.cus_num=p.cus_num
     group by c.cus,c.cus_Lname

答案 2 :(得分:0)

select CONCAT(CONCAT(cus_fname, ' '), cus_lname) as customer_name, 
    count(p.pet_id) as number_of_pets,
    max(p.pet_lastvisit) as last_visit
from customer c, pet p
where c.cus_num=p.cus_num
group by customer_name
order by customer_name desc