Skip to content

Tag: sql

Extract the record for last hour for specific date

I am trying to extract the last hour (TKT_DT) record for number of tickets (TKT_DN) from sales table (PS_TKT_HIST) for specific date (BUS_DAT). I have the following code but it extracts the number of tickets (TKT_NO) for each hour. I want to filter the last hour only. Here is the code I used: I get the flowin…

Group By Month between two dates

I have a table that lists all employees and their respective start and end dates I want to be able to count the number of active employees in each month. Is there a way to do this via a single query (eg groupBy) rather than generating multiple queries for each month? As an example, the table above should retu…

What does back to back table references mean in SQL from clause

I am looking at a query from crystal reports and it shows a table name immediately followed by a table name. see below if that didn’t make sense but I am trying to understand what this syntax is/does? thank you in advance for any insight Answer The 2nd name is the alias. It allows you to refer to the ta…

How to select the best item in each group?

I have table reports: In human language: there are reports for each month. Each report could be in XML or CSV format. There could be 1-2 reports for each month in unique format. I want to select the reports for all months, picking only 1 file for each month. The XML format is more preferable. So, expected out…