I need to find first in and last out time for all employees from a table. I have tried the following query. This query return the records for a particular employee. But I have to find the data for all employees. Sample Table data: Answer you can use this.
Dynamically SELECT a column based on value of row at first of month
The following query: Returns the following sample data: Where on the first of the month, Confirmed = Y, I need to return the Declared column for that month. Note, Confirmed = Y will only exist on the first of the month. That column is blank in all other cases Otherwise, I need to return each Interim column fo…
sql nested “sum (case when) or” select query
I have a select query where I am trying to sum a value based on multiple criteria, grouped by dimension. The output will be the sum of the time greater than 30, 90, or 365 days based on the category, grouped by category. I can’t crack the syntax for this, I hope you can help! The concept looks something…
How do I count the customers that made more than a purchase?
I have a table called order that looks like this: I am trying to display: 1.Total count of customers that bought 1 time only (that went to the store in one occasion, it could have been that they bought multiple items but it is only a one time event) 2.Total count customers that bought more than 1 time (that w…
How Select record with where clause with math using ActiveRecord?
I want to return a list of records whose created_at more than 5 seconds before its updated_at i.e. But this syntax doesn’t appear to work. Getting the error: Answer You didn’t say what database you are using, but with MySQL you can the TIMEDIFF function for this: If you are using Postgres:
How to get student attendance_status by date using sql query?
In my database I have this data. Now I want to query and fetch data based on date and group by roll_number. I am able to fetch all the data using But I am not able to find what I want. I am learning databases and SQL. I used group by option like below but my result is not what
SQL code to project how many clients will reach age 55 each month for a year
I am trying to get the number of clients who are currently >= age 55, which I’ve managed, but next I want to find out how many people will be >= 55 in a month’s time, then in 2 month’s time etc up to …
Not allowed to return a result ? stored procedure mysql
CREATE TABLE ZAMOWIENIA( id_zamowienia INT PRIMARY KEY NOT NULL, id_uzytkownika INT, kwota_zamowienia DECIMAL(10,2)); INSERT INTO ZAMOWIENIA VALUES (1,1,20), (2,4 ,5), (3,3,100), (4,1,300), …
Just get one data if duplicate (not DISTINCT)
I have the following result from a query in mysql (headers: depicao, arricao): EDDH, EDDK EDFH, EDDL EDDS, EDDH EDDK, EDDH My problem is now, that I just want one of the rows, IF the data exist in …
Add rows to SQL table based on a list of values
So I have a table like this and an attribute list – (‘attr1’, ‘attr2’, ‘attr3’). id | attr_name | attr_value —————————- 1 | attr1 | val1 1 | attr2 | val2 1 | attr3 …