查询中的GROUP BY子类型重复值

时间:2019-10-03 08:56:05

标签: sql oracle group-by

(?i)nodejs|(?i)nestjs

尝试执行以下代码:

create or replace type album_type as object 
(albumTitle         varchar(50),
 albumPlaytime      number(3), -- minutes
 albumReleaseDate   date, 
 albumGenre         varchar(15),
 albumPrice         number(9,2),
 albumTracks        number(2),
member function discountPrice return number)
 return integer)
not instantiable not final 
/
create or replace type disk_type under album_type 
( mediaType         varchar(10),
 diskNum            number(2), -- number of disks
 diskUsedPrice      number(9,2),
 diskDeliveryCost   number(9,2), 
overriding member function discountPrice return number)
/
create or replace type mp3_type under album_type
(downloadSize   number, -- size in MB
 overriding member function discountPrice return number)

insert into albums values (
    disk_type (
       'The Essential Bob Dylan', 99,'8-Jul-2016','Pop', 37.00, 32, 
        artist_array_type(
            artist_type('Bob Dylan','Composer'),             
            artist_type ('Bob Dylan','Vocals')),         
        review_table_type (             
            review_type ('shawn','24-jul-2018','wife loved it!', 5
    ),      review_type ('reuben','2-aug-2019','great compilation of some of his most known songs', 5)),
    'Vinyl', 2
, null
, 11.00)
        )

但是问题是结果输出的值重复

the resulted output

以下代码:

SELECT t1.albumTitle ,  t2.artistName 
FROM albums t1, TABLE(t1.albumArtists ) t2  
WHERE  value(t1) IS OF (mp3_type) GROUP BY t1.albumTitle , t2.artistName  ORDER BY t1.albumTitle;

没有重复的值

但没有输出子类型t2.artistName

尝试执行以下代码:

SELECT t1.albumTitle 
FROM albums t1, TABLE(t1.albumArtists ) t2  
WHERE  value(t1) IS OF (mp3_type) GROUP BY t1.albumTitle  ORDER BY t1.albumTitle;

ORA-00979:不是GROUP BY表达式 00979. 00000-“不是GROUP BY表达式”

0 个答案:

没有答案