Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Newbie question

BJ008BJ008 Posts: 4Member
[b][red]This message was edited by BJ008 at 2004-11-4 11:58:0[/red][/b][hr]
[b][red]This message was edited by BJ008 at 2004-11-4 11:28:47[/red][/b][hr]
Hi,

I have table with four columns (A, B, C, D).
I need something like this :

SELECT COUNT(A) FROM MyTable GROUP BY A, B, DISTINCT(C), DISTINCT(D)

By this query I want to say : I want to group rows with same A, same B, unique C, unique D.
But I cann't use DISTINCT in GROUP BY clause. How can I write it using legal SQL query ???

I will really thanful you if you help me, much thanks.




Comments

  • infidelinfidel Posts: 2,900Member
    : Hi,
    :
    : I have table with four columns (A, B, C, D).
    : I need something like this :
    :
    : SELECT COUNT(A) FROM MyTable GROUP BY A, B, DISTINCT(C), DISTINCT(D)
    :
    : But I can use DISTINCT in GROUP BY clause. How can I write it using legal SQL query ???
    :
    : I will really thanful you if you help me, much thanks.

    Using distinct in a group by clause doesn't even make sense. When you say "group by" something that means find all the records that have the same value in that field and aggregate them together.

    I'm not exactly sure what you're trying to do. Your example doesn't make enough sense for me to guess.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • BJ008BJ008 Posts: 4Member
    : : Hi,
    : :
    : : I have table with four columns (A, B, C, D).
    : : I need something like this :
    : :
    : : SELECT COUNT(A) FROM MyTable GROUP BY A, B, DISTINCT(C), DISTINCT(D)
    : :
    : : But I can use DISTINCT in GROUP BY clause. How can I write it using legal SQL query ???
    : :
    : : I will really thanful you if you help me, much thanks.
    :
    : Using distinct in a group by clause doesn't even make sense. When you say "group by" something that means find all the records that have the same value in that field and aggregate them together.
    :
    : I'm not exactly sure what you're trying to do. Your example doesn't make enough sense for me to guess.
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]
    :
    :

    I mean this : I want to group rows with same A, same B, unique C, unique D.
  • infidelinfidel Posts: 2,900Member
    [b][red]This message was edited by infidel at 2004-11-15 7:54:15[/red][/b][hr]
    : : : Hi,
    : : :
    : : : I have table with four columns (A, B, C, D).
    : : : I need something like this :
    : : :
    : : : SELECT COUNT(A) FROM MyTable GROUP BY A, B, DISTINCT(C), DISTINCT(D)
    : : :
    : : : But I can use DISTINCT in GROUP BY clause. How can I write it using legal SQL query ???
    : : :
    : : : I will really thanful you if you help me, much thanks.
    : :
    : : Using distinct in a group by clause doesn't even make sense. When you say "group by" something that means find all the records that have the same value in that field and aggregate them together.
    : :
    : : I'm not exactly sure what you're trying to do. Your example doesn't make enough sense for me to guess.
    : :
    : :
    : : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    : :
    : : [code]
    : : $ select * from users where clue > 0
    : : no rows returned
    : : [/code]
    : :
    : :
    :
    : I mean this : I want to group rows with same A, same B, unique C, unique D.
    :

    Ok, how about:

    select ...
    from table
    group by A, B

    Unless you explicitly group by a column, it is not grouped, so there's no need to use any distinct qualifier for the other columns.

    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]



Sign In or Register to comment.