Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MYSQL


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





How To Get Data Based On The Month And Year??


"select month(str_to_date(fmonth,'%M')) from company where id=2;"
(Query 1)
The fmonth in company has values like 'March,October etc,...'

this would give result as 4 for april (fmonth values in company table).

i have another table which has values based on the date.(Transaction table)

i want to fetch the values from the transaction table based on the date which is greater than the month of selected value fetched by the first query and of the year of current year....

i tried the query ,

"select *from transaction where date_format(transdate,'%Y %m') >=
date_format(curdate(),'%Y %m');"
This query returned the data which has a transdate >= 2006-10

i know that i have to combine the two query,but couldn't get those things.




View Complete Forum Thread with Replies

Related Forum Messages:
Query For Month Data Based On Occurance Against Master List
I have a query running nicely. Now I'm trying to expand it.

It pulls the data from a table based on matching the id with another table and part of the grouping is by month and 2 other criteria. Now I'm trying to get the data pulled by month to pull only the info where the id matches the master file AND the FRANID's pulled are the same for each month. I'm trying to get a comparisson across times, but not every month has all FRANID's, depending on when they were entered and I ony want data that exists with matches over set months, starting for now with 12, perhaps also for 6 and 3 next time.

I've simplified what I'm doing above, but it is detailed below.....

View Replies !
Current MONTH And YEAR
Having an event-calendar table, and an attribute event_date, How can i retrieve the events of the current month and current year based on that field? .....

View Replies !
Dates, Month And Year
I want to query by month and year a field of date type:

eg. : 2005-08-18

so i will receive 2005 or 2004 or 2006 and the months 01, 02 03 ...

How this query will be?

select * from table substr(date, 0, 4) //for year

select * from table substr(date, 6, 2) //for month

View Replies !
Comparing Month And Year From A Timestamp
select all artices where the month of the timestamp = $given_month AND year of the timestamp = $given_year.

To accomplish the above I tried (note: blog_date is the timestamp in the db):

SELECT * FROM blog_entries WHERE MONTH(blog_date) = 'january' AND YEAR(blog_date) = 2009.

The error I'm getting is unknown column MONTH(blog_date), etc....

View Replies !
Selecting All Rows By Year And Month
I have a lot of records for invoices. Each record has a field with DATE datatype, so YYYY-MM-DD format is set.

I`d like to get all invoices from 2008-10 period. What is the best approach for that?

I see solutions like this:

SELECT *
FROM invoices
WHERE DATE_FORMAT(date,'%Y-%m') = '2008-10';

or:
SELECT *
FROM invoices
WHERE YEAR(date) = 2008 AND MONTH(date) = 10;

or add two new additional cols to table invoices (month and year). I need good performance for that because this records is really quite a lot and getting more each month.

View Replies !
Getting Year, Month, Day From A Timestamp Field.
I'm currently programming my own blog, however I've come into a minor problem with the way I want to display my archived posts. I want to display a list by year (2006, 2005, etc.) then a list of months for the specified year (nov, dec, etc.).

I've searched the documentation and have been unable to find a sql command that retrieves parts of a timestamp. ie; timestamps are in YYYYMMDDHHMMSS format. I'm looking to extract the year, or month from that. ie; SELECT YEAR(timestamp) AS y FROM blog_posts GROUP BY y ORDER BY y DESC. or replace YEAR() with MONTH(). You get the idea.

I did find a YEAR() command in the documention but it doesn't look to be what I'm looking for, since I was unable to find it's system commands MONTH() and DAY().

View Replies !
Format Datetime (day, Month Date And Year)
How to format this datetime format

2003-11-09 08:58:59

to

Sun, November 9 2003 8:58am

View Replies !
Display Period In Month Into Period In Year And Month
If i've below table,
NoOfMonth
------------
9
12
36
16
...

How to query to make it my result as follow,
NoOfMonth | Period_InYear | Period_InMonth
-------------------------------------------
9 | 0 | 9
12 | 1 | 0
36 | 3 | 0
16 | 1 | 4
...

View Replies !
Selecting Records Between Two Dates Occurring In Certain Month Of A Year
I have trouble with querying events for my calendar. It consists of as simple fields as these (only relevant fields to my question):

event_id (INT10)
event_date_begin (DATE)
event_date_end (DATE)

now, an example row:

event_date_begin has a value of 2008-12-28, event_date_end has a value of 2009-01-04

How can I retrieve this row, knowing only the current month and year, say I want to display all the events in my calendar happening / continuing in January 2009 (1/2009). So this query should be able to fetch my example row, because the event is still occurring in January (ending date in 2009-01-04).

I can display one month / year at a time, so the query always has those, for example 01, 2009.

I think what I need, is some kind of "function" to check, if certain month and year exist between those two date fields..?

The closest I've got so far is:

'SELECT event_id, event_date_begin, event_date_end FROM events WHERE 12 BETWEEN MONTH(event_date_begin) AND MONTH(event_date_end) OR MONTH(event_date_begin) = 12 ORDER BY event_id ASC';

This query returns all the necessary rows, also if the event continues to the next month, but when the year changes it stops working correctly..

View Replies !
Date Range :: Month, Year And Date In Separate Columns
I have a database where the date is stored in 3 different collums month, day, year. A am trying to retrieve data by a date range something like "1-1-2005" - "1-1-2007" or something but had quite some difficulty in doing it but I found a way and I am not sure that it is the best way but it appears to work well. Let me know what you think.

"SELECT * FROM database " +
"WHERE datey*365+DAYOFYEAR(CONCAT(datey, '-', datem, '-', dated)) " +
"BETWEEN " + StartDate + " AND " +
"EndDate + " " +
"ORDER BY datey, datem, dated;"

NOTE: StartDate and EndDate use the same formula of (year*365)+dayofyear

View Replies !
Single Query For No Of Hits "Today", "This Month", "This Year"
Is it possible to construct a single query that fetches the no of pageviews "today", "this month", "this year" and "total since start"?

The table is very simple, one field for Date (YYYY-MM-DD) and one for the no of pageviews this day.

If not, would it be much slower/faster to divide the query into 4 different queries?

View Replies !
Percentage Of 2 Year Data
I am having the toughest time trying to figure out how to get a percentage from my tables.

1. I Have 12 tables from 2005 named January2005, February2005 etc. up to December2005.
I also have 12 tables for 2006 name January2006 etc.

2.In these tables is a column named Result and the value is either Won or Lost.
I am counting how many times is says Won or Lost and getting a Total for each Month.
"Select Count(Result) From January2005 Where Result = 'Won';

3.I am getting a percentage for 2005 and 2006 just fine.
SELECT Round(((WonTotal)/Val((WonTotal)+(LoseTotal))*100))
FROM WinTotal, LoseTotal;

This is the problem: I need to take 2005 and 2006 and combine them to get a total percentage of Won.

View Replies !
Field Data Updated Automatically Every Year
I have a membership management system in php that stores members private information in individual mysql database fields. One of them is age. I can have users enter their age and this value is stored in the database field for age. the problem here is that this value is not supposed to remain always the same but it has to increase by one every year obviously. Is there a function in mysql that auto-increments the value of that field automatically every year?

View Replies !
Last Month Of Data
I am trying to limit my query to the last month of data. Below is the limiter that I have used. The query is accepted by the server, and returns data, but does not limit the data. Any suggestions as to how to correct this?

where issueddate > date_sub(current_date,interval 1 month)

View Replies !
Pulling Data From Last Month
I can't seem to to make the query call out last months highest clicks. I read the INTERVAL and subdate but don't know how to apply it.....

View Replies !
Pulling All Data From Specific Month
I want to pull out all the data entries I've made for a specific month by using a $_GET method (archived.php?month=october). My field time rows look like "1161065143".

How can I do a mysql_query for this?

Here's what I have so far:

mysql_query("SELECT * FROM entrynote WHERE time = '$date' SORTED BY time DESC

View Replies !
Mysql Is Giving The Previous Month, Not This Month, Strange!
PHP Code:

$myquery = @mysql_query("select year(sendon) as yr, month(sendon) as mth, count(*) as hits from ebook_user group by yr, mth");
    while ($myrow = mysql_fetch_array($myquery)) {
    $mymonth =  $myrow['mth'];
    $myyear =  $myrow['yr'];
    $myhits = $myrow['hits'];
    print '<td bgcolor="#E7E7E5">'.date("M", mktime(0, 0, 0, $mymonth, 0, $myyear)).' '.$myyear.' </td><td bgcolor="#E7E7E5"> '.$myhits.'</td>'
    }


The above code is printing the previous month instead of current month ... can any one help?

View Replies !
Retreaving Data Based
I have tables called room_status and room_info

room_status= room_id : date : status

room_info= room_id : type : rate

What I want to do is only make an entry in room_status when
a room is booked, as it is obviously available otherwise(duh) but
I don't know how to format a SELECT statement to bring back
rooms available on a specific date by only returning results from
the room_information table which do not have an entry in the room_status
table for a specific date, which is the case if I don't formally record that
a room is available.

View Replies !
Query Based On Data Of 3 Tables
this is what I've been trying to implement:

I have, say, three tables.

One is a user table, with id, username, etc
Second is a question table with Question ID, Question, Category etc
And third is an "answers" table that keeps answers given by the users. It has the classic id key, and Question id and User Id columns.

What I want to do is this:
Select a random question of category 1 lets say from the questions table for which user X has no record of answering in the answers table.

View Replies !
Month By Month Count Of Records
I need to generate record counts for each month in a year, just one year at a time, but a full year at a glance. I am thinking 12 hits to the DB is perhaps not the most idea way to do it, is there a way to rip this out in one go?

View Replies !
Collecting Month By Month Results
does anyone have thoughts on how to do queries that produce date bins? I do things like DATE_FORMAT( created_time , '%M %Y' ) AS date and then group by date

thing is that when there is nothing in a particular month, no row is returned ...

So a query like this: Code:

View Replies !
Schedule Data Extractions Based On Requirements
I'd like to SCHEDULE a task to run automatically once per week that would EXTRACT all records from PHPBB_USERS which have either been newly created that week or were edited by the client within the same period.

The data would extract to a COMMA-DELIMITED file which would then be automatically emailed using the PHP mail command to an intended recipient so that she can MERGE the datafeed into a larger and more complex offline database.

Not entirely sure how this would be done, but I'm sure CRON would somehow get involved with the task.

View Replies !
Update Column Data Based On Another Table
I've got 2 tables: 'city' that list over 2000000 rows and 'profile' where each row are associated to a city.

What I want to do is to update cities popularities based on profile without having to scan the hole 2000000 rows of 'city'.

So is it possible to make those 2 query in one so I do not need to do a php loop:

SELECT city, COUNT(city) FROM profile GROUP BY city;

then

UPDATE city SET popularity = COUNT(city) WHERE city.city_id = profile.city

View Replies !
Determining Which Table To Query Based On Data Within Tables
I have 2 tables:

default_categories
column 1: category_id
column 2: category_name
column 3: category_parent

custom_categories
column 1: custom_cat_id
column 2: custom_cat_name
column 3: custom_cat_parent

The custom_categories table won't necessarily have anything in it but if it does, I need to choose the data from the custom_categories table over the data from the default_categories table.

So if the default category has 3 rows with IDs | names:
123 | Dogs
456 | Cats
789 | Fish

And the custom category has 1 row with IDs | names:
456 | Very Cute Cats

I want my query of these 2 tables to produce the following IDs | names:
123 | Dogs
456 | Very Cute Cats
789 | Fish

I've tried joins like the one below but they aren't working because if there is no custom_cat_id, it won't give me the result for the default category_id.


MySQL
SELECT *
        FROM default_categories
        LEFT JOIN custom_categories ON category_id = custom_cat_id
        WHERE category_parent = ''
        AND custom_cat_parent = ''
        ORDER BY $order_by $sort




View Replies !
How Do I Replace Data In An Existing Table - Based On A Column With An Identifier
Each record in the table I want to update has a unique identifier: products_model. For a given model number, I want to replace its image, which is located in a field called products_image.

The file with the new data is a .txt file, a sample of which looks like this:

v_products_modelv_products_imageEOREOR
5361453614.jpgEOREOR
5361553615.jpgEOREOR
5372453724.jpgEOREOR

The beginning part of the table looks like this:
+----------------------------------+---------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------------------------+---------------+------+-----+---------------------+----------------+
| products_id | int(11) | NO | PRI | NULL auto_increment |
| products_type | int(11) | NO | | 1 | |
| products_quantity | float | NO | | 0 | |
| products_model | varchar(32) | YES | MUL | NULL | |
| products_image | varchar(64) | YES | | NULL | |
| products_price | decimal(15,4) | NO | | 0.0000 | |
| products_virtual | tinyint(1) | NO | | 0 | |

From what I've read over the past few days...I think I need to:
(a) delete the EOREOR column from the text file;
(b) use the LOAD DATA INFILE command somehow, telling it to ignore the first line of column headers in the text file.

View Replies !
ORDER Based On One Field But LIMIT Based On Another?
Say I have a table with students and their grades, and I want to get the students with the top 10 grades, but the result to be sorted based on their name. How would I do that?

View Replies !
Selecting Data Form One Table That Is Based On An Entry In Another Table
This is the code I am using:

***********
SELECT co_name,city,country,logo_small FROM $info WHERE $info.co_name=$categories.co_name AND WHERE $categories.everyday_wear='y' ORDER BY co_name ASC
***********

I am using a while loop in php to loop through all of the records but no records are being displayed. What am I missing? Do I need to use a JOIN statement?

View Replies !
Select Data From 1 Table Based On Criteria From Another Table
is it possible to select all the data in one table based on a criteria from another table?

for instance i want to select all the therapist from massage_therapist WHERE massage_schedule.finish > 0.
i don't want merged results. i just need to list all therapist based on the where criteria from a different table.

these two tables have the therapist_id in common.

View Replies !
Get Year
i'm having problems getting the proper year.
my current date is :
november xx 2006, if i add 3 months from this date...
the outcome should be february xx 2007.

View Replies !
%Year%
What does %Year% represent in a query?Code:

SELECT * FROM `table` WHERE `field` NOT like '%Year%'

I checked google and the forum, but it seems to strip the %%.

View Replies !
How To Get The Current Year
I'm a new bee to Mysql and i want to know how to get the Current year from the system date and then also know how to get the rows which are greater than the fetched year.

View Replies !
Year Range
I am writing a document download system. In my database I have a From year, and a To year. These are the periods a particular document covers. For example, 2007-2008 or just 2007-2007.On my main page I want to list all documents that fall within the current year. So, I will need to list all documents that contain the year 2007 between the From and the To years....I hope this makes sense!I've tried doing:

"SELECT * FROM docs WHERE " & strcurrentyear & " YEAR(ffrom) BETWEEN YEAR(fto)"

View Replies !
Group By Year
I have a column in my table with this format. 2007-06-22 00:00:00. Is there any way for me create a mysql statement that will group the tables by year? I have a column with a number and I want to get a count of the number of positive numbers in this column and group them by year.

View Replies !
Date Format :: Put Year In The Last
When I set up the database, I set a date field to type: date and gave it 8 characters. It wants to save in the format 0000-00-00, but I want the year to be last. Is there a way to do this?

View Replies !
Generate A List Of Year
i'm trying to make a list of year using integer table, but currently, i'm stuck..

the result that i'm looking for is like this,

2000,
......,
......,
2009

View Replies !
Sorting By Price Or Year
I am currently developing a used car website. When a user browses our inventory it displays the cars to him by the id it was entered, IE when entered into the database each car is assigned a number 1 , 2 , 3 so on. When the browse button is clicked it only sorts the vehicles by Car ID#. Is there anyway I can have it sort by price , or year , or make? Is the sorting in the database or in the scripting?

View Replies !
Year Field Type
My question is, how do I prevent default data being entered into this field when I don't want to enter a year for the given row?

View Replies !
Selecting A Record One Year Old
$query_articles = "SELECT * FROM ".db('prefix')."articles WHERE published = 1 AND category!='1' AND SUBSTRING(position, 1, 1) != '2' AND (date<=DATE_SUB(NOW(), INTERVAL 1 YEAR)) order by date desc LIMIT 1";

date=DATE_SUB(NOW(), INTERVAL 1 YEAR)


View Replies !
How To Represent A Calendar Year??
I am trying to represent a calendar year in a mySQL table. I need to represnt each month and all the days for each month in a certain year. Can anyone help me with this? I am basically making a small on-line booking application using php and mySQL.

View Replies !
Adding 1 Year To All Times
suppose that

dbX -> tableX

id columnX
1 1190815874
2 1192975748
3 1196695027
4 1196796789

how can i add 1 year all value where year is 2007 ?

my sql do not run

UPDATE `tablex` SET `columnx` = DATE_ADD(`columnx`, INTERVAL 1 YEAR)
WHERE DATE_FORMAT(FROM_UNIXTIME(`columnx`),'%X')) = 2007;

View Replies !
Getting Dates From: Week, Year
Is it possible to retrieve the dates that belong to a certain week in a year?

If I query for Week 23 and Year 2006...I'd like to get this returned.

5-6-2006
6-6-2006
7-6-2006
8-6-2006
9-6-2006

View Replies !
Date Issue With The New Year.
SELECT *
FROM sermons
ORDER BY date DESC
And its spitting out the following code. the problem is that I want the new year then December of last year then November etc.

Here is what it spits out now

12-24-2006
12-10-2006
12-03-2006
11-26-2006
11-26-2006
11-22-2006
11-15-2006
11-12-2006
11-12-2006
11-08-2006
11-05-2006
11-05-2006
11-01-2006
10-29-2006
10-29-2006
10-25-2006
10-22-2006
10-22-2006
10-15-2006
10-15-2006
10-08-2006
10-08-2006
10-08-2006
10-07-2006
10-06-2006
10-05-2006
10-04-2006
10-03-2006
10-02-2006
10-01-2006
10-01-2006
01-07-2007
01-03-2007

View Replies !
Leaving YEAR Fields Empty
I have a form which includes the option for users to enter a year into a YEAR defined field. The field is optional, so how do I ensure that if they leave it blank, it does insert the default 2000 value into the year field

View Replies !
Cannot Sort By Year On Timestamp Field
I have a query on a timestamp field:

select DATE_FORMAT(created, '%M %d, %Y') as created from Notes order by created DESC

The sorting works for dates within a year but then I get older years first:

October 17, 2007
October 9, 2007
March 28, 2008

View Replies !
Select Year From Varchar Field
A cartographer customer of mine has populated a MySQL varchar field with information about the date in which his maps were created. He wants to pull out the date and sort records by it.

The rules he uses for approximating dates are as follows, where YYYY signifies the date he wants to sort by, zzzz represents garbage:

1) Explicit year:

YYYY

2) Year approximated:

{YYYY} zzzz

or (YYYY) zzzz

e.g. {1984} 1987 and he wants 1984

3). Circa:

ca. YYYY

---- Therefore what I would like to do, is pull out only the first four numbers, and use those numbers to sort on.

SELECT [grab the first four numbers only from column "Period"] AS year FROM maps ORDER BY year.

View Replies !
MYSQL Fiscal Year Type
This is the SQL statment to generate by calender year type... which mean
from the january to December...

String sql = "SELECT TO_CHAR(REQUEST_DATE, 'MM') AS MONTH, SUM(REQUEST_TYPE)
AS HITS " +
"FROM REQUEST " +
"WHERE BRANCH=? AND CATEGORY=? " +
"AND TO_CHAR(REQUEST_DATE, 'YYYY')=? " +
"GROUP BY TO_CHAR(REQUEST_DATE, 'MM')";

I need the SQL statment to generate by fiscal year type...
Which is from the 1 April 06 to 31 March 07

just like when i choose 1st April 07, it will show me 1 April 07 to 31 March 08.

View Replies !
Count Posts In A Year Per User
I need a query that will count posts in a year per user ...

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved