How to print concurrent visitors on a website using sql query? - mysql

In this database, there are data entries which shows login time and logout time of visitors. I want to print the number of concurrent visitors at each entry using sql query preferably by using self join.An example The table named "visitor" has 3 columns i.e user_id, login_time amd logout_time. I want to create a 4th column which will show the number of concurrent users during the login_time of that particular entry. In the given example, I have manually displayed the number of concurrent users but I want to write a query which will automatically display the number of concurrent users

Related

Data manipulation in MySQL using window functions

I've a table in my database with record of an agent. The record looks like
Here, Site ID is a place where the Agent 1001 visits at logs himself in at TimeIn and then logs out of that site at TimeOut and raises some tickets and its corresponding amount. Now, If the site is not changed then I want to aggregate these records as shown in the table given below:
I am using MySQL database to do this. Using window functions I can find out consecutive matching Site ID and then mark it as some flag_variable (let's say 1) in a new column.
Now, for these rows where flag=1, I want to update current row TimeOut = next row Timeout. For three or more consecutive record of same Site ID this approach will not work, then we should need a recursive approach I guess.
My question is how can we do this update in the current table and remove redundant records in the table using MySQL syntax.

Creating a running aggregate of users to date in MySQL query

I have table that has users with unique IDs and a date field for when the account was created. I am able to generate a query that can tell me how many people signed-up within a particular week of the year. However, what I am interested in is the number of users that signed up historically + that week. Does anyone have any ideas?
Constraint, I have read only access to the database and can not write new tables and columns.
I've successfully gotten the counts broken up by week, but I can't not figure out how the table can refer to itself to get a running total.

Access data vba

I have a database where users updates info and get their count shown after every save. But when I done a split database the users are able to see total users count instead of individual count can some one help

How to put insertion limit in MySQL database table entries according to certain condition?

Is there a way to limit insertion in a database table? In the Student_Applications table, a certain Roll# cannot submit more than 6 applications? How will I do this in MySQL?
Let's say I want Student#1 to submit total of 4 applications while in the same table Student#2 can submit 6 applications?
If it is a web based application for example php based then you can do the following.
In your student_application table, there must be student_id. Before saving inserting your form entries into database, you can simply check COUNT(student_id) in student_application and if it is >= 6, instead of inserting the data you re-direct user to a page or show popup that user has exceeded limit of inserting applications.

New records since last query in MySQL View

I am looking for a way to create a View that when queried will automatically only retrieve new records since the last query. My tables have a timestamp field for all entries, so for a simple example I can
SELECT * WHERE timestamp >= 'blah'
but I don't know how to determine what blah should be from the last query. So if the View was queried at 11:00 and then again at 12:00, the query at 12:00 should only return records added since 11:00. And so on... This all needs to be accomplished in the View, the end user should simply be able to query the View and get the results.
Is this possible?
There are two ways:
Store last access date time in database per user persistent session
table, if you have one. On next view call to database, use the
previous latest access time in the session to filter rows starting
from.
Store last access date time in user virtual session at client
environment. On every call to server, send last access date time as
well. So that server uses it to filter rows starting from.
I prefer to use second option that process won't write any data in database tables.
As there may be an unread record that slips through undetected (say it came less than a second since the last one accessed, so it has the same timestamp), set a column to auto increment (typically labelled id) and check for entries using it e.g. in PHP save the last accessed record in a $lastId variable, and use:
$sql="SELECT * WHERE `id` > '$lastId'";