Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 27th, 2012, 09:33 AM
dlopez dlopez is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2011
Posts: 64 dlopez User rank is Corporal (100 - 500 Reputation Level)dlopez User rank is Corporal (100 - 500 Reputation Level)dlopez User rank is Corporal (100 - 500 Reputation Level)dlopez User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 13 h 33 m 11 sec
Reputation Power: 3
SQLITE help

Hello,

I'm building dashboard in php, retrieving data from multiple database types. Right now, my focus is on a Spiceworks SQLITE database.

I'm not familiar with the functions in Sqlite. I'm trying to query the monthly ticket total, group the total by month and store that in an array. I'm not for sure about the SQL syntax to do this.... I could just select * from the table and have the php process the data, but I would rather the data be processes when the query executes. Right now, I'm using something that has DATEPART().

PHP Code:
 SELECT 
     DatePart
(mmcreated_at) as date
FROM
     tickets
WHERE DateDiff
(yyyycreated_atGetDate()) = 0
Group by DatePart
(mm,created_at)
Order by DatePart(mmcreated_at


Could anyone help me out with what syntax that I would need to accomplish this?

Thanks!

Reply With Quote
  #2  
Old January 27th, 2012, 10:26 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,370 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 21 m 40 sec
Reputation Power: 4140
Quote:
Originally Posted by dlopez
I'm not familiar with the functions in Sqlite.
http://www.sqlite.org/lang_corefunc.html


Code:
SELECT STRFTIME('%m',created_at) AS mm
     , COUNT(*)
  FROM tickets
 WHERE created_at >= DATE('now','start of year')
GROUP
    BY mm
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Last edited by r937 : January 27th, 2012 at 10:29 AM.

Reply With Quote
  #3  
Old January 27th, 2012, 10:44 AM
dlopez dlopez is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2011
Posts: 64 dlopez User rank is Corporal (100 - 500 Reputation Level)dlopez User rank is Corporal (100 - 500 Reputation Level)dlopez User rank is Corporal (100 - 500 Reputation Level)dlopez User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 13 h 33 m 11 sec
Reputation Power: 3
Thanks for that. I'm needing to count the total for each individual month, however. I added ... ,COUNT(*) as count FROM tickets... etc. so total number of 08, 09, 10, etc.

Should I do the actual sorting on the PHP side? Or does SQLITE have a way of doing this? I'm not an SQL expert, that's for sure.

Reply With Quote
  #4  
Old January 27th, 2012, 11:00 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,370 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 21 m 40 sec
Reputation Power: 4140
Quote:
Originally Posted by dlopez
Should I do the actual sorting on the PHP side? Or does SQLITE have a way of doing this?
use ORDER BY

i left it out until i heard back that GROUP BY mm worked

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > SQLITE help

Developer Shed Advertisers and Affiliates



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 On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap