473,626 Members | 3,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HELP -- SQL not exactly a cross-tab NEED 2 columns/fields result

Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 105
Message-ID: <nl************ ***********@bgt nsc04-news.ops.worldn et.att.net>
Date: Tue, 09 Dec 2003 17:09:39 GMT
NNTP-Posting-Host: 12.72.193.239
X-Complaints-To: ab***@worldnet. att.net
X-Trace: bgtnsc04-news.ops.worldn et.att.net 1070989779 12.72.193.239 (Tue, 09 Dec 2003 17:09:39 GMT)
NNTP-Posting-Date: Tue, 09 Dec 2003 17:09:39 GMT
Organization: AT&T Worldnet
Xref: intern1.nntp.au s1.giganews.com mailing.databas e.mysql:138765

Environment is MySQL 3.23.33, PHP Version 4.3.2.

Have included a couple of extra columns here in an attempt to clarify what
I am trying to do. In the table rid is a unique, auto-increment. The fields
date_created and date_updated are datetime format yyyymmdd hh:mm:ss.
Passing a begining and ending date format of mm-yyyy as begdate 06-2003
and endate 11-2003 (those can be 1-24 months and cross a year boundry)
into a single table query like ;

*Code:*

SELECT (date_format(da te_created,'%m - %Y')) as RptMonth
, SUM(IF(date_cre ated != \"0000-00-00\", 1,0)) AS NEW
, date_format(dat e_created,'%m - %Y')) as Created
, SUM(IF(date_upd ated != \"0000-00-00\", 1,0)) AS Upd
, date_format(dat e_updated,'%m - %Y')) as Updated
from activity_table
where (
(date_format(da te_created,'%Y% m') between \"$begdate\" and
\"$enddate\" ) or
(date_format(da te_updated,'%Y% m') between \"$begdate\" and \"$enddate\" )
)
group by rid

Grouping by rid just to ensure that all rows are returned and to use the
SUM function. Injected > and >> manually in the following table to
highlight
what I am trying to get as results. First result example set is a series
of rows
(small representative set is shown here).

*Code:*

Activity For period of Jun/2003 to Nov/2003
RptMonth New Created Upd Updated Total
07 - 2003 1 07 - 2003 0 00 - 0000 1
07 - 2003 1 07 - 2003 0 00 - 0000 2
07 - 2003 1 07 - 2003 0 00 - 0000 3
07 - 2003 1 07 - 2003 0 00 - 0000 4
07 - 2003 1 07 - 2003 0 00 - 0000 5
07 - 2003 1 > 07 - 2003 1 >> 09 - 2003 6
08 - 2003 1 08 - 2003 0 00 - 0000 7
08 - 2003 1 08 - 2003 0 00 - 0000 8
08 - 2003 1 08 - 2003 0 00 - 0000 9
09 - 2003 1 09 - 2003 0 00 - 0000 10
10 - 2003 1 10 - 2003 0 00 - 0000 11
10 - 2003 1 10 - 2003 0 00 - 0000 12
10 - 2003 1 10 - 2003 0 00 - 0000 13
10 - 2003 1 10 - 2003 0 00 - 0000 14
10 - 2003 1 10 - 2003 0 00 - 0000 15
11 - 2003 1 11 - 2003 0 00 - 0000 16

I am certain that a query can return a table that is like my desired
output, but I am absolutely stuck on geting the results set. Desired
output would be a table that looks like the following, note that the >>
wouldn't actually be displayed it is added here, just to show where that
row highlighted above would get counted. Also the Total is decremented
by that 1. In the actual output I wouldn't even display the Created or
Updated date.

*Code:*

Activity For period of Jun/2003 to Nov/2003
RptMonth New Created Upd Updated Total
07 - 2003 6 > 07 - 2003 0 00 - 0000 6
08 - 2003 3 08 - 2003 0 00 - 0000 9
09 - 2003 1 09 - 2003 1 >> 09 - 2003 10
10 - 2003 5 10 - 2003 0 00 - 0000 15
11 - 2003 1 11 - 2003 0 00 - 0000 16

I have tripped and ripped and fallen all over myself on this, and think
that it is something like - maybe i have to concat and sum by date_xxx
and beg-enddate or a lengthy passed array or a mysterious moon phase
(gasp):

*Code:*

SELECT (date_format(da te_created,'%m - %Y')) as RptMonth
, SUM(IF(date_cre ated != \"0000-00-00\", 1,0)) AS NEW
, date_format(dat e_created,'%m - %Y')) as Created
, SUM(IF(date_upd ated != \"0000-00-00\", 1,0)) AS Upd
, date_format(dat e_updated,'%m - %Y')) as Updated
from activity_table
where (
(date_format(da te_created,'%Y% m') between \"$begdate\" and
\"$enddate\" ) or
(date_format(da te_updated,'%Y% m') between \"$begdate\" and \"$enddate\" )
)
group by RptMonth


Anybody offer any thoughts on this? Welcome all of them, as your idea
might just kick my brains cells in another direction.

TIA
email nospam1001 at nonags dot com

Jul 19 '05 #1
0 1883

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
2518
by: Martin Euredjian | last post by:
I could use a shove in the right direction... I'm using the Dreamweaver MX suite to build a website for my business. At first I threw something together quickly just to get going. I now need to replace that with something more refined. It seems that using PHP would be a part of that. I quickly learned that frames are problematic. I'm also reading that using tables (for layout) isn't the best idea either. And, then, PHP and DHTML
9
4396
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with the microsoft HTML workshop utility, lets call it c:\path\help.chm. My question is how do you launch it from the GUI? What logic do I put behind the "help" button, in other words. I thought it would be os.spawnv(os.P_DETACH,...
6
2638
by: moi | last post by:
hi, im fairly new to c++ and as part of a module at uni im learning it. i know the basics i suppose, but as our final hand-in we have to alter code we wrote for an earlier assignment to use classes as opposed to structures. the program basically modelled a simple polygon using point, line and polyogon structures. and had various functions to find the properties of the shape such as area, perimeter, etc. the question reads along the...
10
2045
by: Robert | last post by:
Where can i find a free web- based VC++ course? (also i've to dowanload it) I'm interested also in VB and C++ thanks, Robert
28
3293
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical make-believe challenge in order to avoid confusing the issue further. Suppose I was hosting a dinner and I wanted to invite exactly 12 guests from my neighborhood. I'm really picky about that... I have 12 chairs besides my own, and I want them all...
9
1932
by: Nicole | last post by:
Okay, so I was working primarily in dreamweaver and the site looks very good in both IE (our customers primarily use this) and Firefox (my new 'thing'), but I ran it through the validator and noticed some startling things-- I have eight errors keeping me from being valid html 4.01 transitional. Please help! What would a style sheet look like for this page, as it is one of about 30. I want this site to be fully compliant, but I've never...
4
2239
by: Norman Fritag | last post by:
Hi there, >>>__ 1020.83, 2305.22, 1176.86, 755.12, 123.41 __ 1976.1, 1325.99, 947, 718.03, 414.32 __ 1020.83, 1976.1, 352.5, 947, 718.03, 366.98 Their IDs were as ---------------------------------------------- __ 508671, 508789, 508850, 513108, 514552 __ 507960, 509289, 509149, 511454, 512759__ 508671, 507960, 510436, 509149, 511454, 513633 <<<
3
6274
by: rsouza | last post by:
Hi. Recently here in my work we added the following code in the Global.asax file to handled the session expired and redirect users to the home of the site explaining them the occurred (some thing like "Your session has expired, please restart your navigation."). public void Session_Start(Object sender, EventArgs e) { if(Session.IsNewSession && Request.Headers != null &&
2
1827
by: deshg | last post by:
Hey everyone, I am a php programmer originally and am just helping a friend of mine update their website that they paid a designer (well that's what he called himself!) to do ages ago. I have built the whole site (ASP.NET using VB.NET) but am having problems on the most basic thing! I have a page which querys an MS SQL database and takes url variables to query it, so it takes the value of keyword= and perpage= (eg from...
53
8366
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script language="javascript" type="text/javascript">
0
8259
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8696
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7188
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6119
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5571
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4195
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.