Query Help

  • Hello, i was searching for some help, and maybe someone could help me with my problem!

    I have to get a MAX from an Account Balance..

    I'm using a query to get all balances, and its working Perfect, but the problem comes when trying to get the MAX...

    that's he query I use :

    SELECT Balance, Customer.FName, Customer.Address

    FROM Accounts INNER JOIN

    Account_mm_Customer ON Accounts.AccountID = Account_mm_Customer.AccountID INNER JOIN

    Customer ON Account_mm_Customer.CustomerID = Customer.CustomerID

    GROUP BY Customer.FName, Customer.Address, Balance

    I'm using SQL Server 2005

    if anyone can help plz let me know

    I appreciate it

  • Something like

    SELECT MAX(Balance) AS BalanceMax, Customer.FName, Customer.Address

    FROM Accounts INNER JOIN

    Account_mm_Customer ON Accounts.AccountID = Account_mm_Customer.AccountID INNER JOIN

    Customer ON Account_mm_Customer.CustomerID = Customer.CustomerID

    GROUP BY Customer.FName, Customer.Address --, Balance



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • LutzM (6/3/2011)


    Something like

    SELECT MAX(Balance) AS BalanceMax, Customer.FName, Customer.Address

    FROM Accounts INNER JOIN

    Account_mm_Customer ON Accounts.AccountID = Account_mm_Customer.AccountID INNER JOIN

    Customer ON Account_mm_Customer.CustomerID = Customer.CustomerID

    GROUP BY Customer.FName, Customer.Address --, Balance

    Yep I tried that but still giving me almost same result, not working :/

  • The syntax is correct. It returns data. So it IS working.

    The fact you're expecting other results implies you're looking for a different query then. 😉

    Since we don't know your data nor can we look over your shoulder, it's hard to help you any further without some more detailed information.

    Maybe you could have a look at the first link in my signature and post table def and sampel data in a ready to use format together with what you're looking for.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • LutzM (6/3/2011)


    The syntax is correct. It returns data. So it IS working.

    The fact you're expecting other results implies you're looking for a different query then. 😉

    Since we don't know your data nor can we look over your shoulder, it's hard to help you any further without some more detailed information.

    Maybe you could have a look at the first link in my signature and post table def and sampel data in a ready to use format together with what you're looking for.

    I know that the Syntax is correct. and that it returns data, but you can't say that it IS working, because its not, it should give only one record which is the max of "Balance" but its giving me the whole records, all balances. So its Not Working :/

    Anyone can also offer an opinion? thank you!

  • Please re-read my previous post regarding some test data and help us help you.

    It should return MAX(Balance) per Customer.FName and Customer.Address. So I would expect one row per customer. If there are multiple combination of FName and Address then yes, there will be more than one row.

    If that's not what you're looking for, please provide more detailed information (table def, sample data, expected result, like I asked for in my previous post).



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • me.hacked (6/3/2011)


    Hello, i was searching for some help, and maybe someone could help me with my problem!

    I have to get a MAX from an Account Balance..

    I'm using a query to get all balances, and its working Perfect, but the problem comes when trying to get the MAX...

    that's he query I use :

    SELECT Balance, Customer.FName, Customer.Address

    FROM Accounts INNER JOIN

    Account_mm_Customer ON Accounts.AccountID = Account_mm_Customer.AccountID INNER JOIN

    Customer ON Account_mm_Customer.CustomerID = Customer.CustomerID

    GROUP BY Customer.FName, Customer.Address, Balance

    I'm using SQL Server 2005

    if anyone can help plz let me know

    I appreciate it

    SELECT TOP 1 Balance, Customer.FName, Customer.Address

    FROM Accounts INNER JOIN

    Account_mm_Customer ON Accounts.AccountID = Account_mm_Customer.AccountID INNER JOIN

    Customer ON Account_mm_Customer.CustomerID = Customer.CustomerID

    GROUP BY Customer.FName, Customer.Address, Balance

    ORDER BY Balance DESC

    ???? is that what you mean?

    MM



    select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);

  • Forum Etiquette: How to post Reporting Services problems
  • [/url]
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • [/url]
  • How to Post Performance Problems - by Gail Shaw
  • [/url]

  • Thank mate, ur the man 🙂 Solved 🙂

  • Viewing 8 posts - 1 through 8 (of 8 total)

    You must be logged in to reply to this topic. Login to reply