MYSQL
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives Mailing Lists MYSQL

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old June 18th, 2008, 09:50 AM
Grant Giddens
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Do I need to use GROUP BY to do this?

Hi,

  I have a table where I keep sales transactions, so I'm trying to do a query that will count the number of transactions per day.

My test data looks like:

--
-- Table structure for table `sales_activity`
--

CREATE TABLE `sales_activity` (
  `sales_id` int(11) NT NULL auto_increment,
  `sales_date` datetime NT NULL default '0000-00-00 00:00:00',
  `sales_type` tinyint(4) NT NULL default '0',
  PRIMARY KEY  (`sales_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTINCREMENT=11 ;

--
-- Dumping data for table `sales_activity`
--

INSERT INT `sales_activity` VALUES (1, '2008-06-15 13:00:00', 1);
INSERT INT `sales_activity` VALUES (2, '2008-06-15 13:00:00', 1);
INSERT INT `sales_activity` VALUES (3, '2008-06-15 13:00:00', 1);
INSERT INT `sales_activity` VALUES (4, '2008-06-15 13:00:00', 1);
INSERT INT `sales_activity` VALUES (5, '2008-06-15 13:00:00', 2);
INSERT INT `sales_activity` VALUES (6, '2008-06-15 13:00:00', 2);
INSERT INT `sales_activity` VALUES (7, '2008-06-16 13:00:00', 1);
INSERT INT `sales_activity` VALUES (8, '2008-06-16 13:00:00', 1);
INSERT INT `sales_activity` VALUES (9, '2008-06-17 13:00:00', 1);
INSERT INT `sales_activity` VALUES (10, '2008-06-17 13:00:00', 1);
       

I would like to get a count of the number of transactions where transaction id=1 for each date.

ie, the result set should look like:

2008-06-15    4
2008-06-16    2
2008-06-17    2


What type of query do I need to get that information?

Thanks!

Reply With Quote
  #2  
Old June 18th, 2008, 10:31 AM
Ian Simpson
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Do I need to use GROUP BY to do this?

I happen to have worked on a similar query this morning, so it's in my
mind :)

SELECT SUBSTRING(sales_date,1,10), ****(sales_id)
FRM sales_activity
WHERE sales_type = 1
GRUP BY SUBSTRING(sales_date,1,10);

should do the trick.

Tue, 2008-06-17 at 18:21 -0700, Grant Giddens wrote:
Hi,

  I have a table where I keep sales transactions, so I'm trying to do a query that will count the number of transactions per day.

My test data looks like:

--
-- Table structure for table `sales_activity`
--

CREATE TABLE `sales_activity` (
  `sales_id` int(11) NT NULL auto_increment,
  `sales_date` datetime NT NULL default '0000-00-00 00:00:00',
  `sales_type` tinyint(4) NT NULL default '0',
  PRIMARY KEY  (`sales_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTINCREMENT=11 ;

--
-- Dumping data for table `sales_activity`
--
Ian Simpson
System Administrator
MyJobGroup

This email may contain confidential information and is intended for the recipient(s) only. If an addressing or transmission error has misdirected this email, please notify the author by replying to this email. If you are not the intended recipient(s) disclosure, distribution, copying or printing of this email is strictly prohibited and you should destroy this mail. Information or opinions in this message shall not be treated as neither given nor endorsed by the company. Neither the company nor the sender accepts any responsibility for viruses or other destructive elements and it is your responsibility to scan any attachments.

Reply With Quote
Reply

Viewing: Web Development Archives Mailing Lists MYSQL > Do I need to use GROUP BY to do this?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT