Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Count records question in MySQL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Count records question in MySQL

    I have two tables that are linked on the Customer_Id, I'm trying to count the records in the child table that only match the current date .

    This is what I have so far but gives me a count of all records not just the matching ones.
    Code:
    Count( currentdate() = activity_log_new.DATE_CREATED )  AS Count_current_Dates,
    All help greatly appreciated.
    Regards
    Keith Hubert
    Alpha Guild Member
    London.
    KHDB Management Systems
    Skype = keith.hubert


    For your day-to-day Needs, you Need an Alpha Database!

    #2
    Re: Count records question in MySQL

    Does this work?

    Code:
    SELECT COUNT(*) AS Count_current_Dates
    FROM activity_log_new
    WHERE CurrentDate() = activity_log_new.DATE_CREATED
    edit:

    You could also do this:

    Code:
    SUM( IF (CurrentDate() = activity_log_new.DATE_CREATED, 1, 0) ) AS Count_current_Dates,
    No idea what kind of impact a sum ( if (...) ) is going to have on your query. But ^^^ in case you can't use the where clause. This assumes that I used the SUM function properly...
    Alpha Anywhere latest pre-release

    Comment


      #3
      Re: Count records question in MySQL

      Hi Sarah,

      Thanks for getting back to me on this.

      I assume the WHERE creates a filter. I already have a very complex filter on the parent table, not sure how to fit this into what I already have.

      Your second example looks like it returns a value, maybe I could use that as an indicator rather than an actual count.
      Regards
      Keith Hubert
      Alpha Guild Member
      London.
      KHDB Management Systems
      Skype = keith.hubert


      For your day-to-day Needs, you Need an Alpha Database!

      Comment


        #4
        Re: Count records question in MySQL

        I went and looked at COUNT. It counts things that are not NULL. So if you modified your test to this:

        Code:
        COUNT( IF(currentdate() = activity_log_new.DATE_CREATED, 1, NULL) )  AS Count_current_Dates,
        it should give you the count you're looking for.
        Alpha Anywhere latest pre-release

        Comment


          #5
          Re: Count records question in MySQL

          Hi Sarah,

          Many thanks for your explanation. This works perfectly. I'm now able to change an image if the value is greater than 0.

          The object of the application is to monitor phone calls made to members. So, in addition to counting calls made today we would like to display a field value, if the call was NOT answered.

          The choices in the Contact_Result field are;
          No Answer No Message
          No Answer Message Left
          Call Engaged
          Answered Add Action
          Answered Add Note

          Please can you help. I did try to IM you but you have blocked that avenue.
          Regards
          Keith Hubert
          Alpha Guild Member
          London.
          KHDB Management Systems
          Skype = keith.hubert


          For your day-to-day Needs, you Need an Alpha Database!

          Comment


            #6
            Re: Count records question in MySQL

            I did turn off IM. I don't like it.

            If the call is "Call Engaged", does that mean the phone was answered? You can use the IF to create that field. I assume your No Answer No Message and No Answer Message Left are TINYTINT(1). If they are TINYINT(1) then 0 = false and 1 = true...

            Code:
            SELECT
                IF (NO_ANSWER_NO_MESSAGE = 1 OR NO_ANSWER_MESSAGE_LEFT = 1, "Unanswered", "Answered") AS WAS_ANSWERED
            FROM Contact_Result;
            If your No Answer No Message and No Answer Message Left columns are NULL if the call was answered, then you could test the NULL state instead:

            Code:
            SELECT
                IF ( NO_ANSWER_NO_MESSAGE IS NOT NULL OR NO_ANSWER_MESSAGE_LEFT IS NOT NULL, "Unanswered", "Answered") AS WAS_ANSWERED
            FROM Contact_Result;
            Without knowing what states indicate the call was answered - not much more I can assist with here! This should help you get started, though. You can put whatever test case you need in the IF to determine if the call was Answered or Unanswered. You can also just return a 0 or 1 in the IF. Alpha will treat the field as a logical field if you return a 1 or 0.

            If you're writing portable SQL queries, documentation on IF is here: http://wiki.alphasoftware.com/Portability+Functions

            If you're writing MySQL specific queries, IF is here: http://dev.mysql.com/doc/refman/5.5/...functions.html
            Alpha Anywhere latest pre-release

            Comment


              #7
              Re: Count records question in MySQL

              If the call is "Call Engaged", does that mean the phone was answered? You can use the IF to create that field. I assume your No Answer No Message and No Answer Message Left are TINYTINT(1). If they are TINYINT(1) then 0 = false and 1 = true...

              Code:
              SELECT
                  IF (NO_ANSWER_NO_MESSAGE = 1 OR NO_ANSWER_MESSAGE_LEFT = 1, "Unanswered", "Answered") AS WAS_ANSWERED
              FROM Contact_Result;
              If your No Answer No Message and No Answer Message Left columns are NULL if the call was answered, then you could test the NULL state instead:

              Code:
              SELECT
                  IF ( NO_ANSWER_NO_MESSAGE IS NOT NULL OR NO_ANSWER_MESSAGE_LEFT IS NOT NULL, "Unanswered", "Answered") AS WAS_ANSWERED
              FROM Contact_Result;
              Without knowing what states indicate the call was answered - not much more I can assist with here! This should help you get started, though. You can put whatever test case you need in the IF to determine if the call was Answered or Unanswered. You can also just return a 0 or 1 in the IF. Alpha will treat the field as a logical field if you return a 1 or 0.

              If you're writing portable SQL queries, documentation on IF is here: http://wiki.alphasoftware.com/Portability+Functions

              If you're writing MySQL specific queries, IF is here: http://dev.mysql.com/doc/refman/5.5/...functions.html
              Alpha Anywhere latest pre-release

              Comment


                #8
                Re: Count records question in MySQL

                Originally posted by Keith Hubert View Post
                Hi Sarah,

                Many thanks for your explanation. This works perfectly. I'm now able to change an image if the value is greater than 0.

                The object of the application is to monitor phone calls made to members. So, in addition to counting calls made today we would like to display a field value, if the call was NOT answered.

                The choices in the Contact_Result field are;
                No Answer No Message
                No Answer Message Left
                Call Engaged
                Answered Add Action
                Answered Add Note

                Please can you help. I did try to IM you but you have blocked that avenue.
                I did turn off IM. I don't like using it.

                You can use an IF to test your data fields to create a new field that contains the information you're looking for:

                Code:
                SELECT
                    IF(Contact_Result IN ('No Answer No Message','No Answer Message Left'), 'Unanswered', 'Answered') AS WAS_ANSWERED
                FROM ... ? ...
                I suppose you could also use LIKE...

                Code:
                    IF(Contact_Result LIKE 'No Answer%', 'Unanswered', 'Answered') AS WAS_ANSWERED
                It's a toss-up on LIKE. I like IN better. It's more explicit, despite it's wordiness.

                Woo. I attempted to post on this twice earlier. Got a message that the post had to be reviewed by a moderator first - but logging out & logging back in permits me to post... Not sure if I'm being moderated or if I'm getting bad BB sessions? If they show up - they're wrong. I'll clear them out if they show up.
                Last edited by TheSmitchell; 07-02-2013, 09:24 AM. Reason: Adding missing content
                Alpha Anywhere latest pre-release

                Comment


                  #9
                  Re: Count records question in MySQL

                  Hi Sarah,

                  Thank you for your samples.

                  I used
                  Code:
                  IF(activity_log_new.Contact_Result IN ('No Answer No Message', 'No Answer Message Left', 'Call Engaged') , 'Call Back', 'Answered')  AS NOT_ANSWERED,
                  The result I get is Answered for all records, even if no call has been made. Or for example, the Contact_Result = Call Engaged.

                  Where have I done wrong?
                  Last edited by Keith Hubert; 07-02-2013, 01:55 PM.
                  Regards
                  Keith Hubert
                  Alpha Guild Member
                  London.
                  KHDB Management Systems
                  Skype = keith.hubert


                  For your day-to-day Needs, you Need an Alpha Database!

                  Comment


                    #10
                    Re: Count records question in MySQL

                    If you change your IF expression to this:
                    Code:
                    IF(activity_log_new.Contact_Result = 'No Answer No Message', 'Call Back', 'Answered') AS NOT_ANSWERED
                    ...do you get desired results for records where Contact_Result = 'No Answer No Message'?
                    Last edited by TheSmitchell; 07-02-2013, 02:29 PM.
                    Alpha Anywhere latest pre-release

                    Comment


                      #11
                      Re: Count records question in MySQL

                      I used,
                      Code:
                        IF( Contact_Result = 'Call Engaged' , 'Call Back', 'Answered')  AS NOT_ANSWERED
                      This gave me Answered in all records.
                      Regards
                      Keith Hubert
                      Alpha Guild Member
                      London.
                      KHDB Management Systems
                      Skype = keith.hubert


                      For your day-to-day Needs, you Need an Alpha Database!

                      Comment


                        #12
                        Re: Count records question in MySQL

                        Keith are you trying to get a count of how many record on each day were say engaged, call back and answered?
                        Chad Brown

                        Comment


                          #13
                          Re: Count records question in MySQL

                          Hi Chad,
                          Originally posted by chadbrown View Post
                          Keith are you trying to get a count of how many record on each day were say engaged, call back and answered?
                          Thanks for asking, but no to your question.

                          The idea is that a number of people have to be called on different days. The 'Callers', working online, will be looking at a call list. I'm trying to show on the call list the status of the 'Callee'. (new word?). ie If they have been called today and what was the Result of the Call. This is to try and prevent the same person being called unnecessarily.
                          Regards
                          Keith Hubert
                          Alpha Guild Member
                          London.
                          KHDB Management Systems
                          Skype = keith.hubert


                          For your day-to-day Needs, you Need an Alpha Database!

                          Comment


                            #14
                            Re: Count records question in MySQL

                            What's the value of Contact_Result, then? If you're getting "Answered" for all records, that means none of your Contact_Result values are 'Call Engaged', supposedly.
                            Alpha Anywhere latest pre-release

                            Comment


                              #15
                              Re: Count records question in MySQL

                              Hi Sarah,

                              One record has "Call Engaged" in the table but not shown as such in the grid. You can see that the Red spot indicates a record was created for Today.
                              calls_answered.PNG
                              Only the call to Dr Franklin was made and he was Engaged. (No surprise there).

                              I think I might be doing doing this the wrong way, as there could be a number of calls, all I would need to know is the status of the last call made to that person today.
                              Last edited by Keith Hubert; 07-03-2013, 02:46 PM.
                              Regards
                              Keith Hubert
                              Alpha Guild Member
                              London.
                              KHDB Management Systems
                              Skype = keith.hubert


                              For your day-to-day Needs, you Need an Alpha Database!

                              Comment

                              Working...
                              X