Horizontal filtering(or way to say it)

  • Hello all,

    I've been diggin it everywhere but can't find result, maybe i am searching for the wrong key word in google.

    So say I have a table like the following :

    Country | Manufacturer | Type | QUANTITY

    -----------------------------------------------

    FRANCE | TOYOTA | CAR | 1000

    FRANCE | RENAULT | CAR | 200

    CHINA | TOYOTA | Moto | 50

    THAILAND | BMW | Truck | 600

    GERMANY | MERCEDES | CAR | 2000

    So my first query was to list the country and their quantity. That is easy

    So I will have :

    Country | QT

    --------------------------

    France | 1200

    China |50

    Thailand| 600

    Germany | 2000

    Now I want to have that :

    Country | QT | QT for Toyota | QT fo Renault | Qt for Mercedes | Qt for BMW

    ------------------------------------------------------------------------------------

    France | 1200 | 1000 | 200

    China |50 | 50 |

    Thailand| 600 |

    Germany | 2000 | | 2000

    So to speak.

    I wonder if we can do that in query or should I extract each table and put the data using a programming language (VBA for instance)

    If someone can give me a hint, that would be wonderful

    -david

  • You're looking for PIVOT, or Crosstab query. 🙂 Two methods, same basic result.

    I hate it when I don't know the keyword either, drives me nuts. Let us know if that doesn't get you on your way.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

Viewing 2 posts - 1 through 2 (of 2 total)

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