Results 1 to 12 of 12

Thread: Hi

  1. #1
    Junior Member
    Join Date
    Mar 2007
    Answers
    2

    Smile Hi

    Select AVG(tax) from invoice where type='sales tax'

    even though there are records in the invoice table why does the above query return null


  2. #2
    Contributing Member
    Join Date
    Sep 2006
    Answers
    962

    Re: Hi

    Your query is correct... May be the following factors will affect

    1. May be you don't have a vlaue 'sales tax' in type column (is there any space between sales and tax in your type column ...check it)

    2. May be you have the value in type column like 'Sales Tax'

    3. May be you have the value in type column like 'SALES TAX'

    --------------------
    suresh


  3. #3
    Junior Member
    Join Date
    May 2007
    Answers
    11

    Re: Hi

    ya i agree with suresh, there might only be mismatch in the value that u r giving in single quotes. in SQL what ever u give in single quotes become case sensitive.


  4. #4
    Moderator
    Join Date
    Sep 2006
    Answers
    920

    Re: Hi

    Quote Originally Posted by bbkcdb View Post
    Select AVG(tax) from invoice where type='sales tax'

    even though there are records in the invoice table why does the above query return null
    Dear you have written where type is 'sales tax',

    Is it possible?

    Or it should be like sales_tax

    or SalesTax.

    plz verify.

    Regards,
    Brijesh Jain
    ---------------------------------------------------------
    Connect with me on Skype: jainbrijesh
    Google Plus : jainbrijeshji

  5. #5
    Junior Member
    Join Date
    May 2007
    Answers
    11

    Wink Re: Hi

    Hi Brijesh

    thats possible
    bcoz 'sales tax' is a value thats stored in a column, and we can store values with spaces

    Regards
    Risham


  6. #6
    Moderator
    Join Date
    Sep 2006
    Answers
    920

    Re: Hi

    oh yes,
    I got it.

    then what can be the problem?

    is avg function works on a particular value?

    As i think we run it on a column of a table!

    correct me if i m wrong...

    Regards,
    Brijesh Jain
    ---------------------------------------------------------
    Connect with me on Skype: jainbrijesh
    Google Plus : jainbrijeshji

  7. #7
    Junior Member
    Join Date
    May 2007
    Answers
    11

    Lightbulb Re: Hi

    nothing is wrong with the query,

    as already posted in the thread, anything that u giv in single quotes becomes case sensitive. may me that data stored in column is SALES TAX or Sales Tax or any other combination of upper n lower cases of sales tax. or even it can be salestax. we need to check out n giv the proper value.

    Regards
    Risham


  8. #8
    Contributing Member
    Join Date
    Apr 2007
    Answers
    46

    Re: Hi

    Check the case of the sale tax you have given in the condition.


  9. #9
    Contributing Member
    Join Date
    Jan 2007
    Answers
    33

    Re: Hi

    Which of the following is true of the interpreter?

    _____ It translates instructions written in assembly language into machine language.
    or

    _____ It translates machine language into a high-level language.

    or
    _____ It translates a high-level language into machine language


  10. #10
    Contributing Member
    Join Date
    Apr 2007
    Answers
    46

    Re: Hi

    if the column has varchar or char type you must have to give in the ' '.otherwise it will errored out.


  11. #11
    Expert Member
    Join Date
    Sep 2006
    Answers
    477

    Re: Hi

    The query appears to be right mate. But try adding an and clause in the query to pick non-null columns in the table.

    Select AVG(tax) from invoice where type='sales tax' and tax !=NULL

    It should resolve the issue.

    Cheers!
    Kalayama

    [COLOR="Blue"][SIZE="2"]"If you are not living on the edge of your life, you are wasting space"[/SIZE][/COLOR]

    Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"

  12. #12
    Contributing Member
    Join Date
    Apr 2007
    Answers
    46

    Re: Hi

    hey kalayama,

    watever i m getting,acc. to you if this tax column is null then it will not give the required answer.i m right?

    if yes.then i have checked with one table having null and not null values and i m taking avg of that colum with same type of condition and i m getting the right answer!

    reeta


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact