Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have got the mysql table which includes data about users who visited my web service (IP address, date). The one IP address can be logged in my database only once per day.
What is the best way to create the table contains visits from last month? I want something like:
30.10.2016 | 1457
31.10.2016 | 1604
01.11.2016 | 1590
etc
Sorry for English and maybe the very simple question, first time on stack :)
use this sql code to create a table for last month visitor count.
CREATE TABLE last_mon_visit AS
SELECT DISTINCT date, COUNT(ip_address)
FROM visit
WHERE YEAR(date) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)
AND MONTH(date) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)
GROUP BY date
i would suggest to create view instead of table.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have 2 columns in mysql database i.e. totalRating and ratingDate. There exists multiple values of totalRating against on date e.g. there can be 5 totalRatings on date 2016-08-29, 4 on 2016-08-30. I am using ChartJs to show a graph of totalRating and ratingDate. I want to take the average of totalRatings of a single date and plot it on graph i.e. one totalRating for one date. I am using PHP for the backend. Can somebody help me with the queries?
Using below query you can find average rating for all dates.
select AVG(totalRatings) as avgRating, date from YOUR_TABLE group by date;
I think what you need is the AVG mysql function, your query should be something like:
select AVG(totalRatings) from YOUR_TABLE where date=YOUR_DATE;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to display a database record between two date ranges using PHP-mysql.
I am working on a project in which employees payment record is saved in a table. I want to see what amount has been paid between two dates selected through date-picker.
Try this:
SELECT amount FROM mytable WHERE created_at BETWEEN '2011-12-01' AND '2011-12-07';
Assuming mytable to be the table name, created_at to be the date field and amount to be the amount field.
Hope this helps.
Peace! xD
SELECT amount FROM mytable
WHERE
created_at >= '2011-12-01'
AND
created_at <= '2011-12-07';
If you need the sum of the salary between two dates you can do somethig like:
SELECT sum(salary) as total FROM table_name
WHERE job_date BETWEEN 'dd-mm-yyyy' AND 'dd-mm-yyyy';
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
What i want to do is to limit a user to deposit/withdraw money in the account only 5 times a week , and after the 5 times user must wait next week to be able to deposit again.
I have a table named depuser with the following rows : uid(userid), date(date of dep/witdraw), type(deposit/witdraw) and the amount. thanks in advance
This query will count the # of deposits recorded in the last 7 days, based on your table structure:
SELECT COUNT(uid) AS total_deposits FROM depuser
WHERE `type` LIKE 'deposit' AND
DATE(`date`) <= NOW() AND
DATE(`date`) >= DATE_SUB( NOW(), INTERVAL 7 DAY)`
From here you can compare the total_deposits value returned and make logic decisions.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i am working on php mysql HR application and i have a table with some field like date and salary and incremented salary as shown the below screenshot.
i want a list of a record of each year but some year(date) not in a data base how to get that year as shown in 2nd screenshot
Thanks..
You don't want that result.
In the first place, ID = 2 is already in use for the year 2014; assigning 2013 to it is a bad, bad idea. In the second place, it makes no sense to say that the salary for 2013 is 3500, and the increment is 0, when 2013 isn;'t in the database.
If 2013 is supposed to have those values, then put them in the database.
Otherwise, create a table of years (or a table of integers), and include it in your query with an outer join.
create table years (
yr integer primary key
);
insert into years values
(2012), (2013), (2014), (2015), (2016),
(2017), (2018), (2019), (2020), (2021);
Now you can join those two tables with an outer join. The coalesce() expression isn't strictly necessary with an outer join, but I think it expresses the result you want.
select salaries.id, coalesce(salaries.date, years.yr) as date,
salaries.salary, salaries.increment
from years
left join salaries on
salaries.date = years.yr
where years.yr between 2012 and 2015
order by years.yr;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I've a table with some records like this
date price
01/02/2000 20
02/02/2000 20
03/02/2000 20
the user will choose on my site the date of check-in and out. For example:
check-in: 01/02
check-out: 02/02
I' can i do a function that count the day from 01/02 to 02/02, and sum the price of the 2 days?
Thanks a lot
Pretty simple SQL to calculate the count and sum of the fields between your dates:
SELECT COUNT(*) AS count_dates, SUM(price) AS total_price
FROM your_table
WHERE date >= '01/02/2000'
AND date <= '02/02/2000'
Well, this is not enough infromation what you realy want to get. But my best gues:
SELECT SUM(Price), Count(*) as count_day
Where date>check-in and date<check-out