This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT b.id, | |
b.name | |
FROM Books b, | |
Genres g | |
WHERE g.name = 'Fantasy' AND b.genre = g.id | |
AND b.id in | |
(SELECT ba.book_id | |
FROM Books_Authors ba | |
GROUP BY ba.book_id | |
HAVING count(ba.book_id) >=2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE Authors ( | |
id INT NOT NULL AUTO_INCREMENT, | |
name VARCHAR(225), | |
PRIMARY KEY (id) | |
); | |
CREATE TABLE Genres ( | |
id INT NOT NULL AUTO_INCREMENT, | |
name VARCHAR(225), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m = [12,30,45,9,3,15,2,8] | |
print(m) | |
def my_sort(arr) | |
length = arr.size | |
return arr if length <= 1 | |
n = length-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def look_and_say(rows: 6) | |
# set first row manually | |
row = '1' | |
rows.times do | |
puts row | |
# split row to array to be able to count elements | |
row_chars = row.chars | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
files = Dir.new('.').to_a.keep_if do |file| | |
file =~ /^result\-\d?\.json$/ | |
end | |
def json_objects(files) | |
files.map { |e| JSON.parse(IO.read(e)) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Пусть имеется таблица positions, содержащая поле category_id, | |
-- осуществите выборку из таблицы таким образом, чтобы в результирующую | |
-- таблицу попали по 5 последних записей из каждой категории. | |
-- +----+-------------------+-------------+---------------------+ | |
-- | id | name | category_id | updated_at | | |
-- +----+-------------------+-------------+---------------------+ | |
-- | 9 | Позиция 9 | 1 | 2012-01-09 00:00:00 | | |
-- | 8 | Позиция 8 | 1 | 2012-01-08 00:00:00 | | |
-- | 7 | Позиция 7 | 1 | 2012-01-07 00:00:00 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Следует удалить из таблицы post устаревшие записи, | |
-- таким образом, чтобы остались последние 5 записей | |
-- (по полю updated_at) | |
-- | |
-- Хорошо бы задачу решить при помощи одного запроса | |
-- (многотабличный вариант DELETE с самообъединением). | |
-- | |
-- Предполагается, что количество записей в таблице | |
-- произвольное, поэтому следующий запрос использовать | |
-- не допускается |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def | |
categories | |
cat_tree_elements.each do |i| | |
cat_tree_elements[i].unordered_list_element.list_item_elements.map(&:text) | |
end | |
#puts cat_tree_element[level].unordered_list_elements.map(&:text) | |
end |