Aggregates with DISTINCT/ja

From SQLZoo
Language:Project:Language policy English  • 日本語

Nobel database

COUNT DISTINCT

COUNTとDISTINCTを併用すると異なる値の個数が分かる

1915年は異なる3分野で4人が受賞した:

SELECT yr, subject, winner
  FROM nobel
 WHERE yr=1915
yr subject winner
1915 Chemistry Richard Willstätter
1915 Literature Romain Rolland
1915 Physics Lawrence Bragg
1915 Physics William Bragg

COUNT(subject) の値は 4; COUNT(DISTINCT subject) の値は 3.

SELECT COUNT(subject), COUNT(DISTINCT subject)
  FROM nobel
 WHERE yr = 1915
SELECT COUNT(subject), COUNT(DISTINCT subject)
  FROM nobel
 WHERE yr = 1915
DataWars, Data Science Practice Projects - LogoDataWars: Practice Data Science/Analysis with +100 Real Life Projects
  • Your server today is: Laa-Laa