알고리즘/codefightsDB

16>newsSubscribers

Diademata 2019. 3. 13. 16:01
반응형

You are managing a small newspaper subscription service. Anyone who uses it can subscribe to a large number of different newspapers for a full year or just a half year.


The information about subscriptions is stored in the full_year and half_year tables, which have the following structures:


full_year:

id: the unique subscription ID;

newspaper: the newspaper's name;

subscriber: the name of the subscriber.

half_year

id: the unique subscription ID;

newspaper: the newspaper's name;

subscriber: the name of the subscriber.

Given the full_year and half_year tables, compose the result as follows: The resulting table should have one column subscriber that contains all the distinct names of anyone who is subscribed to a newspaper with the word Daily in its name. The table should be sorted in ascending order by the subscribers' first names.


code>>

/*Please add ; after each select statement*/

CREATE PROCEDURE newsSubscribers()

BEGIN

    SELECT subscriber

    FROM (

        SELECT subscriber FROM full_year WHERE newspaper LIKE '%Daily%'

        UNION

        SELECT subscriber FROM half_year WHERE newspaper LIKE '%Daily%'    

        ) as t

    ORDER BY subscriber;

END

반응형

'알고리즘 > codefightsDB' 카테고리의 다른 글

18>itemCounts  (0) 2019.03.13
17>countriesInfo  (0) 2019.03.13
15>expressionsVerification  (0) 2019.03.13
14>testCheck  (0) 2019.03.13
13>securityBreach  (0) 2019.03.13