perl code

Posted on 2004-11-03
Last Modified: 2012-08-13
#connect to the database
my $dbh = DBI->connect('dbi:mysql:rvsi','','', {RaiseError=>1, PrintError=>1});

# Extract the data from database
my $d = $dbh->selectall_arrayref("SELECT date, qin, qout,yield, reject, lot FROM yield WHERE date BETWEEN '$datef' AND '$datet'");
    print ("Daily Yield Report Summary for '$dev' between '$datef' to '$datet'\n\n");
    print ("Date\t\t", "Qin\t", "Qout\t", "Yield\t", "Reject\t", "Lot\n");

# Print out all the array catch  
foreach my $r(@$d) {
    print join("\t", @$r), $/;

the above perl code allows me to crunch data from the db according to the date given by the
user. jus wan to know can the data be crunch and display each individual day in a month?
eg day 1 all the way to day 30 or 31 another eg is
my $d = $dbh->selectall_arrayref("SELECT date_format(date, '%b'), sum(qin), sum(qout), ((sum(qout)/sum(qin))*100), sum(reject) FROM yieldall WHERE year(date) = '$year' AND job = '$dev' GROUP BY date_format(date, '%b') ORDER BY date")

if possible can anyone provide samples.

thank u.
Question by:TPoly
    LVL 15

    Expert Comment

    I'm not sure exactly what you want. Can you please give more concrete info about what you would like to do?

    LVL 1

    Expert Comment

    That's probably no perl question but about sql. We have to know the used database to tell you the right sql-statement.


    Author Comment

    i'm using mysql as my db
    LVL 15

    Expert Comment

    I'd love to help you out, but I still am unsure of what you want to do -- can you please be more specific about exactly what you are trying to achieve?
    LVL 15

    Accepted Solution

    It also depends on what version of MySQL you are using (some of the very useful date functions have only recently become available), and how you have stored your date information...I would check out this page if I were you:

    What you probably want is something like this:

    SELECT * FROM table WHERE date1 <= date_column AND date2 >= date_column;

    This should select all rows from your database where the date you have stored in date_column is between date1 and date2.


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    use perl to insert into MySQL database 9 104
    perl script help 12 99
    Perl, group, sort, count question 6 101
    PERL - Find newest folder 12 88
    I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
    On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now