从date_time超过30分钟的表中获取mysql结果

时间:2017-12-03 18:16:52

标签: php mysql

我有一个MySQL查询,目标是从包含用户上次活动30分钟或更长时间的配置文件的表中获取所有配置文件ID,或者根本没有记录该用户的活动(活动日志记录在另一个用户中)表)。

问题是:结果是0,即使有超过30分钟的记录,我在这里检查了几个答案,并按照说明进行了但没有结果返回,我认为结构有问题查询。

下面是查询,请注意,个人资料存储在profile_table中,活动存储在activity_table中,并且两者共享相同的ID。

import java.io.File;
import java.util.Scanner;
import java.io.IOException;


public class Part_2 {

    private static int count;

    public static void main(String[] args){

        int D = 0;
        String  line = "";
        int num = 0;
        Scanner keyboard = new Scanner (System.in);
        {
            // Allow the user to enter the name of text file that the data is stored in
            System.out.println("Type in name of the file");
            String fileName = keyboard.nextLine();

            File Fileobject = new File (fileName);
            {
                if (!Fileobject.exists())
                {
                    System.out.println("Error - File does not exist");
                    System.exit(0);
                }

                try {
                    count = 0;
                    if (count < 5)
                    {
                        Scanner fileReader  = new Scanner (Fileobject);

                        System.out.println("\n"+String.format("%-30s",  "Title") +
                                String.format("%-25s", "Author") +
                                String.format("%-25s", "Price") +
                                String.format("%-25s", "Publisher") +
                                String.format("%-25s", "ISBN"));

                        System.out.println(String.format("%-30s", "=====")+
                                String.format("%-25s", "=====")+
                                String.format("%-25s", "=====")+
                                String.format("%-25s", "======")+
                                String.format("%-25s", "===="));

                        while(fileReader.hasNext())
                        {
                            line = fileReader.nextLine();// Read a line of data from text file
                            num = num +1;

                            // The format of each line of data in the text file is as follow: 
                            // Title - Author - Price - Publisher - ISBN
                            // Need to split each line read from file before can process it

                            try {

                                String [] splitArray = line.split("-");

                                // check to make sure there are 4 parts in splitArray 
                                if(splitArray.length == 4)
                                {
                                    // remove spaces
                                    splitArray[0] = splitArray[0].trim();
                                    splitArray[1] = splitArray[1].trim();
                                    splitArray[2] = splitArray[2].trim();
                                    splitArray[3] = splitArray[3].trim();
                                    splitArray[4] = splitArray[4].trim();
                                }

                                if (splitArray[0].isEmpty())
                                {
                                    D++;
                                }

                                if (splitArray[1].isEmpty())
                                {
                                    D++;
                                }


                                if (splitArray[2].isEmpty())
                                {
                                    D++;
                                }


                                if (splitArray[3].isEmpty())
                                {
                                    D++;
                                }


                                if (splitArray[4].isEmpty())
                                {
                                    D++;
                                }


                                System.out.println(String.format(" %-30s", splitArray[0])+
                                        String.format(("%-25s"), splitArray[1])+
                                        String.format(("%-25s"), splitArray[2])+
                                        String.format(("%-25s"), splitArray[3])+
                                        String.format(("%-25s"), splitArray[4]));


                            }
                            catch (Exception e) {
                                    System.out.println("Line delimiter error");
                                    D++;
                            }
                        }
                        System.out.println("");
                        System.out.println("totals");
                        System.out.println("-----------------------------");
                        System.out.println("The total number of books: ");
                        System.out.println("The total costs of books: ");
                        System.out.println("Maximum cost of a book: " );
                        System.out.println("Minimum cost of a book: " );
                        System.out.println("Average cost of a book: " );
                        System.out.println("there are " + D + " error(s) within the text document");
                    }
                }
                catch (IOException e) {
                    // IO error while reading from the file.
                    System.err.println("Error while reading from file ");
                }   
            }
        }
    }
}

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

你可以试试这个查询吗? 从profile_table pr中选择pr.ID,在pr.ID = ac.ID上加入activity_table ac,其中pr.status ='Active',ac.date_time&lt; DATE_SUB(NOW(),INTERVAL 30 MINUTE)