How the second column is not printing out all the region?

Viewed 42

how to fix it so it can print the maximum total price of an order between any two regions, i.e., the suppliers are from one region and the customers are from the other region.

 SELECT region2.r_name, region1.r_name, max(o_totalprice)
    FROM orders
    INNER JOIN customer ON orders.o_custkey = customer.c_custkey
    INNER JOIN nation nation1 ON customer.c_nationkey = nation1.n_nationkey
    INNER JOIN region region1 ON nation1.n_regionkey = region1.r_regionkey
    INNER JOIN supplier ON orders.o_orderkey = supplier.s_suppkey
    INNER JOIN nation nation2 ON supplier.s_nationkey = nation2.n_nationkey
    INNER JOIN region region2 ON nation2.n_regionkey = region2.r_regionkey
    GROUP BY region2.r_name, region1.r_name;

This are table and key for region

CREATE TABLE region (
    r_regionkey  decimal(2,0) not null,
    r_name       char(25) not null,
    r_comment    varchar(152)
);

This are table and key for nation

CREATE TABLE nation (
    n_nationkey  decimal(3,0) not null,
    n_name       char(25) not null,
    n_regionkey  decimal(2,0) not null,
    n_comment    varchar(152)
);

This are table and key for supplier

  CREATE TABLE supplier (
        s_suppkey     decimal(8,0) not null,
        s_name        char(25) not null,
        s_address     varchar(40) not null,
        s_nationkey   decimal(3,0) not null,
        s_phone       char(15) not null,
        s_acctbal     decimal(7,2) not null,
        s_comment     varchar(101) not null
    );

This are table and key for customer

 CREATE TABLE customer (
        c_custkey     decimal(9,0) not null,
        c_name        varchar(25) not null,
        c_address     varchar(40) not null,
        c_nationkey   decimal(3,0) not null,
        c_phone       char(15) not null,
        c_acctbal     decimal(7,2) not null,
        c_mktsegment  char(10) not null,
        c_comment     varchar(117) not null
    );

This are table and key for orders

  CREATE TABLE orders (
        o_orderkey       decimal(12,0) not null,
        o_custkey        decimal(9,0) not null,
        o_orderstatus    char(1) not null,
        o_totalprice     decimal(8,2) not null,
        o_orderdate      date not null,
        o_orderpriority  char(15) not null,
        o_clerk          char(15) not null,
        o_shippriority   decimal(1,0) not null,
        o_comment        varchar(79) not null
    );

my result is like this

AFRICA|AMERICA|131896.49
AFRICA|ASIA|38426.09
AFRICA|MIDDLE EAST|56000.91
AMERICA|AFRICA|260603.38
AMERICA|ASIA|172799.49
AMERICA|MIDDLE EAST|35831.73
ASIA|AFRICA|198978.27
ASIA|EUROPE|301968.79
ASIA|MIDDLE EAST|326565.37
EUROPE|AMERICA|271885.66
EUROPE|ASIA|125705.32
EUROPE|MIDDLE EAST|198665.57
MIDDLE EAST|AMERICA|42011.04
MIDDLE EAST|EUROPE|73315.48

but the answer is like this

AFRICA|AFRICA|408345.74
AFRICA|AMERICA|411255.46
AFRICA|ASIA|422359.65
AFRICA|EUROPE|439687.23
AFRICA|MIDDLE EAST|409770.83
AMERICA|AFRICA|431771.98
AMERICA|AMERICA|466001.28
AMERICA|ASIA|422359.65
AMERICA|EUROPE|439687.23
AMERICA|MIDDLE EAST|409770.83
ASIA|AFRICA|431771.98
ASIA|AMERICA|466001.28
ASIA|ASIA|422359.65
ASIA|EUROPE|439687.23
ASIA|MIDDLE EAST|403464.01
EUROPE|AFRICA|431771.98
EUROPE|AMERICA|466001.28
EUROPE|ASIA|422359.65
EUROPE|EUROPE|439687.23
EUROPE|MIDDLE EAST|409770.83
MIDDLE EAST|AFRICA|431771.98
MIDDLE EAST|AMERICA|362024.17
MIDDLE EAST|ASIA|422359.65
MIDDLE EAST|EUROPE|439687.23
MIDDLE EAST|MIDDLE EAST|397797.8
0 Answers
Related