当前位置:网站首页>True MySQL interview question (XXII) -- condition screening and grouping screening after table connection

True MySQL interview question (XXII) -- condition screening and grouping screening after table connection

2022-06-23 05:47:00 Socialphobia_ FOGO

Select the day to browse the listings 10 Users who have registered for more than one year

A house source platform has two tables to record user information 、 And users to view the listing information .
User table ( The user no. 、 User registration time ).
 Insert picture description here
Browse the table , The field has a log number , The user no. , House source No , Browse date .
 Insert picture description here
problem : Select the day to browse the listings 10 Users who have registered for more than one year .、

give the result as follows :
 Insert picture description here

# Analyze the current day's browsing listings 10 Users who have registered for more than one year 
SELECT 
   Browse date ,
   The user no. ,
  COUNT( House source No ) AS  Number of houses  
FROM
   Browse the table  a 
  JOIN  User table  b USING ( The user no. ) 
WHERE DATE_SUB( Browse date , INTERVAL 1 YEAR) >  Registration time  
GROUP BY  Browse date ,
   The user no.  
HAVING COUNT( House source No ) > 10
原网站

版权声明
本文为[Socialphobia_ FOGO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230355227281.html