1

我们有一个数据库来存储我们的合同客户的详细信息——我们需要每个月检查他们是否已经搬家。因此,尝试运行一个查询,该查询将返回任何在上个月更改了 homebase 的内容。

通过 Unix 套接字使用 mySQL phpmyadmin localhost,for 设置为月份,即 '07-2013' 作为 VARCHAR。

SELECT crewcode, firstname, surname, homebase,'for' AS 'Date'
FROM  `hours` 
WHERE homebase ...

不知道我在这里需要什么?需要查看从 06-2013 到 07-2013 上个月的 homebase 是否发生了变化

非常感谢您的帮助。

4

3 回答 3

0

这是任何有兴趣的人的解决方案:

 SELECT A.employee_ID as crewcode,
        A.emp_firstname, 
        emp_lastname, 
        B.base, 
        B.base_for AS  'Date'
   FROM `hs_hr_employee` as A,
        `employee_base_table` as B 
  where B.base_for=(SELECT DATE_FORMAT(STR_TO_DATE( CURDATE( ) , '%Y-%m-%d' ),'%m-%Y')) 
    AND A.emp_number=B.emp_number 
  group by A.employee_ID    
于 2013-09-12T11:11:15.313 回答
0

您可以尝试加入相同的查询并添加 ON 条件table1.homebase!=table2.homebase

如果此查询返回特定日期的数据

SELECT crewcode, firstname, surname, homebase,'for' AS 'Date'
FROM  `hours` 
WHERE homebase ...

那你可以试试

SELECT a1.crewcode
FROM
(

SELECT crewcode, firstname, surname, homebase,'for' AS 'Date'
FROM  `hours` 
WHERE homebase ... //data for first month )a1

INNER JOIN
(

SELECT crewcode, firstname, surname, homebase,'for' AS 'Date'
FROM  `hours` 
WHERE homebase ... //data for second month
 )a2
ON a1.crewcode=a2.crewcode AND a1.homebase!=a2.homebase
于 2013-09-06T09:53:15.510 回答
0

To look for changes in the last 30 days:

WHERE mydate > curdate() - interval 30 day

To look for changes in the last calendar month:

WHERE year(mydate) = year(curdate()) and month(mydate) = month(curdate()) - 1
于 2013-09-06T09:33:48.520 回答