Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-27-2012, 12:38 AM   PM User | #1
cronic5
New Coder

 
Join Date: Dec 2005
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
cronic5 is an unknown quantity at this point
MySQL query, no experience

I want to be able to turn this:





Into this:





By running a MySQL query. There will be up to 100 different names/accounts that will need to be calculated. I have very little experience in MySQL, mainly because I've never had to use it until now, and even then, this is all I'd need to use it for. There are other ways I could go about this, but for simplicity's sake, let's say it must be done using MySQL.

I know it'd be fairly simple to do for someone experienced in MySQL, and I'd learn to do it myself, but I am somewhat on a short schedule, a few days actually.

Can anyone help me out?

Last edited by cronic5; 10-28-2012 at 04:50 AM..
cronic5 is offline   Reply With Quote
Old 10-27-2012, 03:11 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Are those columns from different *TABLES* in the DB? Or all one table? (If one table, that's a bad DB design, if you care.)

In any case you need to show us the SCHEMA of each table (or the table if only one).

That is, the field names and the data types, by table.

Where are the quote marks coming from, around the various names and values? None of them should be present in the database.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 10-27-2012, 08:32 PM   PM User | #3
cronic5
New Coder

 
Join Date: Dec 2005
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
cronic5 is an unknown quantity at this point
This is actually just a .csv file. It is formatted that way just because that is how it is pulled from the database. I just want to run a query on it in order to add the total times of "duration".
cronic5 is offline   Reply With Quote
Old 10-28-2012, 01:00 AM   PM User | #4
cronic5
New Coder

 
Join Date: Dec 2005
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
cronic5 is an unknown quantity at this point
http://i.stack.imgur.com/ASSvl.png

http://i.stack.imgur.com/gY8J1.png

Maybe this will clear some things up.
cronic5 is offline   Reply With Quote
Old 10-28-2012, 08:11 AM   PM User | #5
cronic5
New Coder

 
Join Date: Dec 2005
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
cronic5 is an unknown quantity at this point
Trying to load the CSV file into a table, I get:

Error Code: 1366. Incorrect integer value: ''Agent Name'' for column 'Agent Name' at row 1

Using:

Code:
LOAD DATA INFILE '1.csv' 
INTO TABLE test
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n'
cronic5 is offline   Reply With Quote
Old 10-28-2012, 11:46 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Last things first: The error message from the LOAD DATE INFILE means that your table test was not created correctly.

For some reason, you created the field `Agent Name` as an INT(eger) field when clearly it should be VARCHAR(50) or something like that.

But I don't understand this, at all.

In your post #4 you wrote "This is actually just a .csv file. It is formatted that way just because that is how it is pulled from the database. " So if you pull the CSV file *FROM* the database WHY in the world are you now trying to put it BACK into the dataabase? I don't understand the reasoning behind that, at all.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 10-29-2012, 12:12 AM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
So you *SEEM* to be saying that http://i.stack.imgur.com/ASSvl.png shows the raw data in your table. You never bother to say what the name of the table is, you know.

And I *THINK* you are saying that http://i.stack.imgur.com/gY8J1.png shows the results you want.

If so, it's trivial.

Code:
SELECT `Agent Name`,`Username`,
       DATE(`Login Time`) AS `Date`,
       SUM ( TIMEDIFF( `Login Time`, `Logout Time` ) ) AS Duration
FROM yourtablename
GROUP BY `Agent Name`, `Username`, DATE(`Login Time`)
ORDER BY `Agent Name`, `Date`
Though this assumes the your Login Time and Logout Time fields in the table are indeed DATETIME values.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:44 AM.


Advertisement
Log in to turn off these ads.