{"id":464615,"date":"2025-06-26T09:00:03","date_gmt":"2025-06-26T09:00:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=464615"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=464615","title":{"rendered":"<span>\u0418\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442 \u0432 \u0437\u0430\u0434\u0430\u0447\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430. \u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9e9\/184\/759\/9e9184759e70877d989e1e4f6d4e6449.png\" width=\"1920\" height=\"1080\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/9e9\/184\/759\/9e9184759e70877d989e1e4f6d4e6449.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9e9\/184\/759\/9e9184759e70877d989e1e4f6d4e6449.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0422\u0430\u0442\u044c\u044f\u043d\u0430 \u041e\u0448\u0443\u0440\u043a\u043e\u0432\u0430, \u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0438 \u0430\u0432\u0442\u043e\u0440\u00a0<a href=\"https:\/\/t.me\/it_tlk\" rel=\"noopener noreferrer nofollow\">\u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u043a\u0430\u043d\u0430\u043b\u0430 IT Talks<\/a>. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0430 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0441\u0430\u043c\u043e\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0438 \u0445\u0430\u0439\u043f\u043e\u0432\u044b\u0445 \u0442\u0435\u043c. \u0421\u043a\u0430\u0436\u0443 \u0447\u0435\u0441\u0442\u043d\u043e, \u044f \u043d\u0435 \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0441\u044c \u043c\u043d\u0435\u043d\u0438\u044f, \u0447\u0442\u043e \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442 \u0437\u0430\u043c\u0435\u043d\u0438\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0438 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<p>\u041c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0446\u0438\u0442\u0430\u0442\u0430: <strong>\u00ab\u0418\u0418 \u043f\u0440\u0438\u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442 \u0442\u0432\u043e\u0438 \u043a\u043e\u043c\u043f\u0435\u0442\u0435\u043d\u0446\u0438\u0438\u00bb<\/strong>. \u0415\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e. \u0422\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0442\u0435\u0431\u0435 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435, \u0430 \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0451 \u0437\u0430 \u0442\u0435\u0431\u044f.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u0440\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0434\u043b\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0430 \u2013 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0441\u0440\u0435\u0434\u043d\u0435\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0418\u0418 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u044d\u0442\u0430\u043f\u0430\u0445.<\/p>\n<blockquote>\n<p>\u0410 \u0435\u0449\u0451\u00a0<a href=\"https:\/\/t.me\/ittalks_aibot\" rel=\"noopener noreferrer nofollow\">\u0443 \u043c\u0435\u043d\u044f \u0432 \u0431\u043e\u0442\u0435<\/a>\u00a0\u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c <strong>\u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0433\u0430\u0439\u0434,<\/strong> \u0433\u0434\u0435 \u0442\u044b \u043d\u0430\u0439\u0434\u0435\u0448\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043f\u044f\u0442\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c \u043d\u0430 PlantUML \u0432 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u0435\u0439\u0441\u0430\u0445 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c.<\/p>\n<\/blockquote>\n<h3>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h3>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0437\u0430\u043a\u0430\u0437\u0430\u043c\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0432 \u043d\u0435\u043a\u043e\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u0412 \u0437\u0430\u043a\u0430\u0437\u0430\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u044b, \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0446\u0435\u043d\u0430, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0443\u0447\u0430\u0441\u0442\u0438\u044f \u0432 \u0430\u043a\u0446\u0438\u0438. \u0410\u043a\u0446\u0438\u0438 \u0431\u044b\u0432\u0430\u044e\u0442 \u0434\u0432\u0443\u0445 \u0432\u0438\u0434\u043e\u0432: 2=1 \u0438\u043b\u0438 3=1 \u2013 \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u043a\u0443\u043f\u043a\u0430 \u0434\u0432\u0443\u0445 \u0438\u043b\u0438 \u0442\u0440\u0451\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043f\u043e \u0446\u0435\u043d\u0435 \u043e\u0434\u043d\u043e\u0433\u043e. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443, \u0433\u0434\u0435 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043a\u0430\u0437\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438 \u0438\u0445 \u0438\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0441\u0443\u043c\u043c\u0430. \u041d\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u0437\u0430\u043a\u0430\u0437\u0430\u0445 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u043e\u0432\u0430\u0440\u044b, \u0438\u0445 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438:<\/p>\n<ul>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435 \u0435\u0441\u0442\u044c \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u044b, \u0442\u043e \u0438\u0445 \u0441\u0443\u043c\u043c\u044b \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0439 \u0441\u0443\u043c\u043c\u0435 \u0437\u0430\u043a\u0430\u0437\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043a \u0441\u0443\u043c\u043c\u0435 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430 \u0441\u0440\u0435\u0434\u0438 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043a\u0430\u0437\u0430 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0430\u043a\u0446\u0438\u0438 2=1 \u0438\u043b\u0438 3=1.<\/p>\n<\/li>\n<li>\n<p>\u0426\u0435\u043d\u044b \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0434\u0432\u0443\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445: \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0446\u0435\u043d\u0430 \u0438 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0446\u0435\u043d\u0430. \u0415\u0441\u043b\u0438 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0446\u0435\u043d\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u0437\u043d\u0430\u043a \u0430\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0437\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0441 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u043f\u043e \u0437\u0430\u044f\u0432\u043a\u0430\u043c \u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\u043e\u043c \u043f\u043e \u0446\u0435\u043d\u0435 \u0441\u0440\u0435\u0434\u0438 \u0442\u0435\u0445, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0430 \u0430\u043a\u0446\u0438\u044f. \u041f\u043b\u044e\u0441 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445, \u0447\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438. \u0410 \u0442\u0430\u043a\u0436\u0435 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043f\u043e \u0430\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e, \u0447\u0442\u043e \u0442\u043e\u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0447\u0435\u0441\u0442\u044c \u043f\u0440\u0438 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0435.<\/p>\n<h3>\u041f\u043b\u0430\u043d \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u0431\u0435\u0437 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u0442\u0441\u044f. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0418\u0418 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b \u0434\u043b\u044f \u0442\u0435\u0431\u044f \u043f\u0440\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0437\u0430\u0434\u0430\u0447. \u041e\u043a\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438 \u2013 \u043c\u043d\u043e\u0433\u043e\u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u0434\u0430\u0447 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438. \u041d\u043e \u043a \u044d\u0442\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c \u0438\u043d\u043e\u0433\u0434\u0430 \u0441\u043b\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0439\u0442\u0438 \u0441\u0430\u043c\u043e\u043c\u0443, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0441\u0440\u0430\u0437\u0443.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0441\u0440\u0430\u0437\u0443 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0418\u0418. \u042f \u043e\u043f\u0438\u0441\u0430\u043b\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0441\u0432\u044f\u0437\u0438, \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u0440\u0435\u0448\u0430\u0435\u043c\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0443 \u043c\u0435\u043d\u044f \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c.<\/p>\n<p>\u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0418\u0418 \u044f \u0431\u044b \u043d\u0430\u0437\u0432\u0430\u043b\u0430 \u043d\u0435\u0443\u043c\u0435\u043d\u0438\u0435 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0438\u0441\u043a\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u0438, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u0440\u0435\u0448\u0438\u0442\u044c \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c. \u0414\u0430\u043b\u0435\u0435 \u044f \u0440\u0430\u0437\u0431\u0438\u043b\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438:<\/p>\n<ul>\n<li>\n<p>\u0421\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0437\u0430\u043a\u0430\u0437\u043e\u0432 \u0441 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430\u043c\u0438, \u0446\u0435\u043d\u0430\u043c\u0438 \u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u043c \u0430\u043a\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0418\u0418:<\/p>\n<ul>\n<li>\n<p>\u0421\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u0434\u043b\u044f \u043d\u0435\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0439\u0442\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0446\u0435\u043d\u0443 \u0441\u0440\u0435\u0434\u0438 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043b\u043e\u0436\u0438\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0441\u0443\u043c\u043c\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0432 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0447\u0430\u0441\u0442\u0438.<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u0438\u043f\u0442\u044b \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c  PostgreSQL<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">-- \u0417\u0430\u043a\u0430\u0437\u044b \u0438 \u0442\u043e\u0432\u0430\u0440\u044b CREATE TABLE order_items (     order_id INT,     product_id INT,     quantity INT );  -- \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0446\u0435\u043d\u044b CREATE TABLE product_prices (     product_id INT,     price DECIMAL(10, 2) );  -- \u0410\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0446\u0435\u043d\u044b CREATE TABLE promo_prices (     product_id INT,     promo_price DECIMAL(10, 2) );  -- \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u0430\u043a\u0446\u0438\u0438 CREATE TABLE product_promotions (     product_id INT,     promo_type VARCHAR(10)  -- \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, '2=1', '3=1' );  -- \u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u0430\u043a\u0446\u0438\u0438 (\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f) CREATE TABLE product_updates (     product_id INT,     promo_type VARCHAR(10) );  -- \u0417\u0430\u043a\u0430\u0437\u044b \u0438 \u0442\u043e\u0432\u0430\u0440\u044b INSERT INTO order_items VALUES (1, 101, 1), (1, 102, 2), (1, 103, 1), (1, 104, 2), (1, 105, 3), (2, 201, 2), (2, 202, 1), (2, 203, 3), (2, 204, 1), (2, 205, 2), (3, 301, 2), (3, 302, 1), (3, 303, 1), (3, 304, 2), (3, 305, 2);  -- \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0446\u0435\u043d\u044b \u0442\u043e\u0432\u0430\u0440\u043e\u0432 INSERT INTO product_prices VALUES (101, 100.00), (102, 200.00), (103, 300.00), (104, 250.00), (105, 150.00), (201, 120.00), (202, 180.00), (203, 260.00), (204, 230.00), (205, 140.00), (301, 160.00), (302, 180.00), (303, 300.00), (304, 350.00), (305, 200.00);  -- \u0410\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0446\u0435\u043d\u044b (\u0435\u0441\u0442\u044c \u043d\u0435 \u0443 \u0432\u0441\u0435\u0445) INSERT INTO promo_prices VALUES (103, 280.00), (104, 220.00), (203, 240.00), (304, 320.00);  -- \u041f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0430\u043a\u0446\u0438\u0439 \u0438\u0437 product_promotions (\u0442\u043e\u043b\u044c\u043a\u043e 2=1 \u0434\u043b\u044f \u0437\u0430\u043a\u0430\u0437\u043e\u0432 1 \u0438 3) INSERT INTO product_promotions VALUES (103, '2=1'), (104, '2=1'), (303, '2=1');  -- \u041f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0430\u043a\u0446\u0438\u0439 \u0438\u0437 product_updates (\u0442\u043e\u043b\u044c\u043a\u043e 3=1 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435 2 \u0438 2=1 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435 3) INSERT INTO product_updates VALUES (202, '3=1'), (203, '3=1'), (204, '3=1'), (304, '2=1');<\/code><\/pre>\n<\/div>\n<\/details>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<h4>\u0428\u0430\u0433 1. \u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438<\/h4>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0438 \u0441\u0430\u043c\u044b\u0439 \u0432\u0430\u0436\u043d\u044b\u0439 \u0448\u0430\u0433 \u2013  \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0443\u044e \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438 \u043e\u0431\u043e\u0433\u0430\u0449\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c\u0438 \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e, \u0447\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0446\u0435\u043d\u0435 \u0442\u043e\u0432\u0430\u0440\u0430 \u043c\u043e\u0433\u043b\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445: \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 (<code>product_prices<\/code>) \u0438 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u043e\u0439 (<code>promo_prices<\/code>). \u0415\u0441\u043b\u0438 \u0434\u043b\u044f \u0442\u043e\u0432\u0430\u0440\u0430 \u0435\u0441\u0442\u044c \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0446\u0435\u043d\u0430, \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0440\u0430\u0441\u0447\u0451\u0442\u0435, \u0430 \u043d\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>COALESCE<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u043e\u0435 \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2013 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 <code>promo_price<\/code>, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0435\u0441\u0442\u044c, \u0430 \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u2013 \u043e\u0431\u044b\u0447\u043d\u0443\u044e <code>price<\/code>.<\/p>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0438 \u0441 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u043c \u0443\u0447\u0430\u0441\u0442\u0438\u044f \u0442\u043e\u0432\u0430\u0440\u0430 \u0432 \u0430\u043a\u0446\u0438\u0438. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0430\u043d \u043b\u0438\u0431\u043e \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>product_promotions<\/code>, \u043b\u0438\u0431\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 <code>product_updates<\/code>, \u0447\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u043c\u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u0427\u0442\u043e\u0431\u044b \u0443\u0447\u0435\u0441\u0442\u044c \u044d\u0442\u043e, \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>COALESCE<\/code>, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044f \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 (<code>product_promotions<\/code>), \u0438 \u043f\u0440\u0438 \u0435\u0433\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u2013 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e (<code>product_updates<\/code>).<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0430\u044f \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435: ID \u0437\u0430\u043a\u0430\u0437\u0430, ID \u0442\u043e\u0432\u0430\u0440\u0430, \u0446\u0435\u043d\u0443 \u0442\u043e\u0432\u0430\u0440\u0430 \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0439 \u0430\u043a\u0446\u0438\u0438, \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0443\u0447\u0430\u0441\u0442\u0438\u044f \u0432 \u0430\u043a\u0446\u0438\u0438 (<code>promo_type<\/code>), \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0435\u0434\u0438\u043d\u0438\u0446 \u0442\u043e\u0432\u0430\u0440\u0430 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435. \u0418\u043c\u0435\u043d\u043d\u043e \u043d\u0430 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u043e\u0438\u0442\u044c\u0441\u044f \u0432\u0441\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u2013 \u043a\u0430\u043a \u0434\u043b\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0438\u0437 \u0440\u0430\u0441\u0447\u0451\u0442\u0430, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445 \u043e\u0431\u0440\u0430\u0442\u043d\u043e (\u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438).<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u044d\u0442\u043e\u0442 \u0448\u0430\u0433 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c. \u041e\u043d \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u043b \u0435\u0434\u0438\u043d\u044b\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0440\u0430\u0441\u0447\u0451\u0442\u043e\u0432. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0447\u0430\u0441\u0442\u044f\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0430\u0441\u0447\u0451\u0442 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u043c \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u043c.<\/p>\n<pre><code class=\"sql\">WITH product_data AS (   SELECT     oi.order_id,     oi.product_id,     COALESCE(pp.promo_price, pr.price) AS effective_price,     COALESCE(promo.promo_type, upd.promo_type) AS promo_type,     oi.quantity   FROM order_items oi   JOIN product_prices pr ON oi.product_id = pr.product_id   LEFT JOIN promo_prices pp ON oi.product_id = pp.product_id   LEFT JOIN product_promotions promo ON oi.product_id = promo.product_id   LEFT JOIN product_updates upd ON oi.product_id = upd.product_id ) SELECT   order_id,   product_id,   effective_price,   promo_type,   quantity FROM product_data ORDER BY order_id, product_id;<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/summary>\n<div class=\"spoiler__content\">\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">order_id<\/p>\n<\/th>\n<th>\n<p align=\"left\">product_id<\/p>\n<\/th>\n<th>\n<p align=\"left\">effective_price<\/p>\n<\/th>\n<th>\n<p align=\"left\">promo_type<\/p>\n<\/th>\n<th>\n<p align=\"left\">quantity<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">101<\/p>\n<\/td>\n<td>\n<p align=\"left\">100.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">102<\/p>\n<\/td>\n<td>\n<p align=\"left\">200.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">103<\/p>\n<\/td>\n<td>\n<p align=\"left\">280.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">2=1<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">104<\/p>\n<\/td>\n<td>\n<p align=\"left\">220.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">2=1<\/p>\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">105<\/p>\n<\/td>\n<td>\n<p align=\"left\">150.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">201<\/p>\n<\/td>\n<td>\n<p align=\"left\">120.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">202<\/p>\n<\/td>\n<td>\n<p align=\"left\">180.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">3=1<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">203<\/p>\n<\/td>\n<td>\n<p align=\"left\">240.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">3=1<\/p>\n<\/td>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">204<\/p>\n<\/td>\n<td>\n<p align=\"left\">230.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">3=1<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">205<\/p>\n<\/td>\n<td>\n<p align=\"left\">140.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">301<\/p>\n<\/td>\n<td>\n<p align=\"left\">160.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">302<\/p>\n<\/td>\n<td>\n<p align=\"left\">180.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">303<\/p>\n<\/td>\n<td>\n<p align=\"left\">300.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">2=1<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">304<\/p>\n<\/td>\n<td>\n<p align=\"left\">320.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">2=1<\/p>\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">305<\/p>\n<\/td>\n<td>\n<p align=\"left\">200.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<\/details>\n<h4>\u0428\u0430\u0433 2. \u0420\u0430\u0441\u0447\u0451\u0442 \u0441\u0443\u043c\u043c\u044b \u0437\u0430\u043a\u0430\u0437\u0430 \u0431\u0435\u0437 \u0443\u0447\u0451\u0442\u0430 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u043f\u043e\u043b\u043d\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0432\u0441\u0435\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0441 \u0446\u0435\u043d\u0430\u043c\u0438 \u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c\u0438 \u0430\u043a\u0446\u0438\u0439, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0441\u0442\u0430\u043b\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u0435\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0430\u043a\u0446\u0438\u044f\u0445. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0443 \u0447\u0430\u0441\u0442\u044c \u0441\u0443\u043c\u043c\u044b \u0437\u0430\u043a\u0430\u0437\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0441\u0443\u043c\u043c \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0431\u0435\u0437 \u0430\u043a\u0446\u0438\u0438. \u0421 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u044d\u0442\u0430\u043f\u0430 \u044f \u043e\u0431\u0440\u0430\u0449\u0430\u043b\u0430\u0441\u044c \u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u043a \u0418\u0418, \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044f, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430:<\/p>\n<blockquote>\n<p> \u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 <code>product_data<\/code> \u0441 \u043f\u043e\u043b\u044f\u043c\u0438: <code>order_id<\/code>, <code>product_id<\/code>, <code>effective_price<\/code>, <code>promo_type<\/code>, <code>quantity<\/code>. \u041c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043a\u0430\u0437\u0430 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0431\u0435\u0437 \u0430\u043a\u0446\u0438\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0435\u0445, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 <code>promo_type IS NULL<\/code>. \u0412\u0435\u0440\u043d\u0438 SQL-\u0437\u0430\u043f\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>order_id<\/code> \u0438 \u0441\u0443\u043c\u043c\u0443 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432, \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 (<code>quantity * effective_price<\/code>). \u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430 \u0437\u0430\u043a\u0430\u0437.   <\/p>\n<\/blockquote>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u043b\u043e\u0433\u0438\u043a\u0443 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438, \u0435\u0441\u043b\u0438 \u0442\u043e\u0432\u0430\u0440 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0430\u043a\u0446\u0438\u0438 \u00ab2=1\u00bb \u0438\u043b\u0438 \u00ab3=1\u00bb, \u0442\u043e \u043e\u043d \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u0437\u0430\u043a\u0430\u0437\u0430 \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c (\u0442.\u0435. \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435 <code>\u0446\u0435\u043d\u0430 \u00d7 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e<\/code>). \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043e\u0441\u043e\u0431\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u043e\u0437\u0436\u0435 (\u043d\u0430 \u0448\u0430\u0433\u0435 3), \u0430 \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0442\u043e\u0432\u0430\u0440\u044b \u0438\u0437 \u0440\u0430\u0441\u0447\u0451\u0442\u0430.<\/p>\n<p>\u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e: \u0441\u0442\u0440\u043e\u043a\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e <code>promo_type IS NULL<\/code>, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0442\u043e\u0432\u0430\u0440 \u043d\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0430\u043a\u0446\u0438\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0440\u0430\u043d\u0435\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 CTE (<code>product_data<\/code>), \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043d\u0443\u0436\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0442\u043e\u0432\u0430\u0440\u0443: ID \u0437\u0430\u043a\u0430\u0437\u0430, \u0446\u0435\u043d\u0430, \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0430\u043a\u0446\u0438\u0438 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e.<\/p>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0435\u0439 \u044d\u0442\u043e\u043c\u0443 \u0444\u0438\u043b\u044c\u0442\u0440\u0443, \u043c\u044b \u043f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0430\u0435\u043c <code>effective_price<\/code> \u043d\u0430 <code>quantity<\/code> \u2013 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u0442\u043e\u0432\u0430\u0440\u0430 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435. \u0417\u0430\u0442\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e <code>order_id<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0437\u0430\u043a\u0430\u0437\u0443.<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u0448\u0430\u0433\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u0431\u0430\u0437\u043e\u0432\u0430\u044f \u0441\u0443\u043c\u043c\u0430 \u0437\u0430\u043a\u0430\u0437\u0430 \u2013 \u0431\u0435\u0437 \u0443\u0447\u0451\u0442\u0430 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043f\u043e\u0437\u0438\u0446\u0438\u0439. \u042d\u0442\u043e \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u00ab\u0447\u0438\u0441\u0442\u0430\u044f\u00bb \u0441\u0443\u043c\u043c\u0430, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u043f\u043e\u0437\u0436\u0435 \u043f\u0440\u0438\u0431\u0430\u0432\u0438\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435 \u0435\u0441\u0442\u044c \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u043e\u0432\u0430\u0440\u044b.<\/p>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0448\u0430\u0433\u0430 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0433\u0434\u0435 \u043d\u0430 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0437\u0430\u043a\u0430\u0437, \u0430 \u043f\u043e\u043b\u0435 <code>main_sum<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0443\u043c\u043c\u0443 \u0432\u0441\u0435\u0445 \u043d\u0435\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0432 \u044d\u0442\u043e\u043c \u0437\u0430\u043a\u0430\u0437\u0435. \u042d\u0442\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0441\u0443\u043c\u043c\u044b.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u0442\u043e\u0440\u043e\u0439 \u0448\u0430\u0433 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0442\u043e\u0432\u0430\u0440\u044b \u043e\u0442 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0443\u043c\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0434\u0447\u0438\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0435 \u00ab\u0446\u0435\u043d\u0430 \u00d7 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u00bb.<\/p>\n<pre><code class=\"sql\">WITH product_data AS (   SELECT     oi.order_id,     oi.product_id,     COALESCE(pp.promo_price, pr.price) AS effective_price,     COALESCE(promo.promo_type, upd.promo_type) AS promo_type,     oi.quantity   FROM order_items oi   JOIN product_prices pr ON oi.product_id = pr.product_id   LEFT JOIN promo_prices pp ON oi.product_id = pp.product_id   LEFT JOIN product_promotions promo ON oi.product_id = promo.product_id   LEFT JOIN product_updates upd ON oi.product_id = upd.product_id ), base_sum AS (   SELECT     order_id,     SUM(effective_price * quantity) AS main_sum   FROM product_data   WHERE promo_type IS NULL   GROUP BY order_id ) SELECT   order_id,   main_sum FROM base_sum ORDER BY order_id;<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/summary>\n<div class=\"spoiler__content\">\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">order_id<\/p>\n<\/th>\n<th>\n<p align=\"left\">main_sum<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">950.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">520.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">900.00<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<\/details>\n<h4>\u0428\u0430\u0433 3. \u0420\u0430\u0441\u0447\u0451\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0443\u043c\u043c\u044b \u0441\u0440\u0435\u0434\u0438 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043b\u0438 \u0441\u0443\u043c\u043c\u0443 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435 \u0431\u0435\u0437 \u0430\u043a\u0446\u0438\u0438, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0437\u0430\u043a\u0430\u0437\u0430. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0435, \u0435\u0441\u043b\u0438 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435 \u0435\u0441\u0442\u044c \u0442\u043e\u0432\u0430\u0440\u044b, \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0432 \u0430\u043a\u0446\u0438\u044f\u0445 \u00ab2=1\u00bb \u0438\u043b\u0438 \u00ab3=1\u00bb, \u0438\u0445 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0432 \u043e\u0431\u0449\u0435\u0439 \u0441\u0443\u043c\u043c\u0435 \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0442\u043e\u0432\u0430\u0440\u044b. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u044d\u0442\u0438\u0445 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u043b\u0430\u0447\u0435\u043d\u0430 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0430\u043a\u0446\u0438\u0438.<\/p>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u043f\u043e\u0438\u0441\u043a\u0443 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043a\u0430\u0437\u0430, \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438 \u0442\u0438\u043f\u0430 \u0430\u043a\u0446\u0438\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 <code>product_data<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u0432\u0430\u0440\u0430\u0445, \u0438\u0445 \u0446\u0435\u043d\u0435 \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0441\u043a\u0438\u0434\u043e\u043a, \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0435 \u0430\u043a\u0446\u0438\u0438 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435.<\/p>\n<p>\u042d\u0442\u043e\u0442 \u0448\u0430\u0433 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0418\u0418 \u043d\u0435 \u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u0430\u0437\u0430. \u041c\u043e\u0439 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u044b\u043b \u0434\u0440\u0443\u0433\u043e\u0439. \u042f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u043b\u0430, \u0447\u0442\u043e \u0418\u0418 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u0430\u043a\u0446\u0438\u0439. \u041d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u043b\u043e\u0441\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0432\u0430\u0440\u0430. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0418\u0418, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043b\u0430 \u043a\u0430\u043a \u0438\u0442\u043e\u0433 \u043f\u043e \u0432\u0441\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u0448\u0430\u0433\u0435:<\/p>\n<blockquote>\n<p>\u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 \u0442\u043e\u0432\u0430\u0440\u0430\u043c\u0438 \u0432 \u0437\u0430\u043a\u0430\u0437\u0430\u0445: <code>order_id<\/code>, <code>product_id<\/code>, <code>price<\/code>, <code>promo_type<\/code>, <code>quantity<\/code>. \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u0430\u0445 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0430\u043a\u0446\u0438\u044f: \u00ab2=1\u00bb \u0438\u043b\u0438 \u00ab3=1\u00bb. \u041d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043a\u0430\u0437\u0430 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u043b\u0430\u0442\u0438\u0442\u044c \u0437\u0430 \u0442\u043e\u0432\u0430\u0440\u044b \u0441 \u0430\u043a\u0446\u0438\u0435\u0439.<br \/>\u041f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c \u0430\u043a\u0446\u0438\u0438: \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u00ab2=1\u00bb, \u0442\u043e \u0438\u0437 \u043a\u0430\u0436\u0434\u044b\u0445 \u0434\u0432\u0443\u0445 \u0435\u0434\u0438\u043d\u0438\u0446 \u0442\u043e\u0432\u0430\u0440\u0430 \u043e\u043f\u043b\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430, \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u00ab3=1\u00bb, \u0442\u043e \u0438\u0437 \u0442\u0440\u0451\u0445 \u2013 \u0442\u043e\u0436\u0435 \u043e\u0434\u043d\u0430. \u0415\u0441\u043b\u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043a\u0440\u0430\u0442\u043d\u043e \u0430\u043a\u0446\u0438\u0438, \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0435\u0441\u044f \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u043f\u043b\u0430\u0447\u0435\u043d\u044b.<br \/>\u041d\u0430\u0434\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0442\u0435 \u0435\u0434\u0438\u043d\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u043b\u0430\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f, \u0438 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0445 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c. \u041d\u0443\u0436\u0435\u043d \u0437\u0430\u043f\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0435\u0440\u043d\u0451\u0442 <code>order_id<\/code> \u0438 \u0441\u0443\u043c\u043c\u0443 \u043a \u043e\u043f\u043b\u0430\u0442\u0435 \u043f\u043e \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u043c \u0442\u043e\u0432\u0430\u0440\u0430\u043c.<\/p>\n<\/blockquote>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>MAX()<\/code> \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c, \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u044e\u0449\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u043e\u0432\u0430\u0440\u044b (<code>promo_type IS NOT NULL<\/code>). \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0438\u0437 \u0432\u0441\u0435\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435 \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u0430\u044f \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430, \u0438 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0437\u0430\u043a\u0430\u0437\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u043b\u0430\u0442\u0438\u0442\u044c \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c \u0430\u043a\u0446\u0438\u0439 \u00ab2=1\u00bb \u0438 \u00ab3=1\u00bb. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043a\u0430\u0436\u0434\u0443\u044e \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0442\u043e\u0432\u0430\u0440\u0430 \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u044e\u0442 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u2013 \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043a\u0430\u0437\u0430 \u0438 \u0442\u0438\u043f\u0430 \u0430\u043a\u0446\u0438\u0438 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0430\u043a\u0438\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0435\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u043b\u0435\u0436\u0430\u0442 \u043e\u043f\u043b\u0430\u0442\u0435. \u0418\u0437 \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b \u0442\u043e\u0432\u0430\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0430\u043a\u0446\u0438\u0438, \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044c \u043e\u043f\u043b\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u0442\u044c \u0442\u043e\u0432\u0430\u0440\u043e\u0432. \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043d\u0430\u0434\u043e \u043e\u043f\u043b\u0430\u0442\u0438\u0442\u044c, \u0438\u0437 \u0432\u0441\u0435\u0445 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0441\u0430\u043c\u044b\u0435 \u0434\u043e\u0440\u043e\u0433\u0438\u0435 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u2013 \u0438\u043c\u0435\u043d\u043d\u043e \u0438\u0445 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0439 \u0441\u0443\u043c\u043c\u0435. <\/p>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0448\u0430\u0433\u0430 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0434\u043d\u043e\u043c\u0443 \u0437\u0430\u043a\u0430\u0437\u0443, \u0430 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <code>promo_amount<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043a\u0430\u0437\u0430. \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u0430 \u0441\u0443\u043c\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u043a \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0441\u0443\u043c\u043c\u0435 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e  \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430.<\/p>\n<pre><code class=\"sql\">WITH product_data AS (   SELECT     oi.order_id,     oi.product_id,     COALESCE(pp.promo_price, pr.price) AS effective_price,     COALESCE(promo.promo_type, upd.promo_type) AS promo_type,     oi.quantity   FROM order_items oi   JOIN product_prices pr ON oi.product_id = pr.product_id   LEFT JOIN promo_prices pp ON oi.product_id = pp.product_id   LEFT JOIN product_promotions promo ON oi.product_id = promo.product_id   LEFT JOIN product_updates upd ON oi.product_id = upd.product_id   WHERE oi.quantity &gt; 0 AND COALESCE(promo.promo_type, upd.promo_type) IS NOT NULL ),  -- \u0420\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0436\u0434\u0443\u044e \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0442\u043e\u0432\u0430\u0440\u0430 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 expanded_units AS (   SELECT     order_id,     promo_type,     effective_price,     ROW_NUMBER() OVER (PARTITION BY order_id, promo_type ORDER BY effective_price DESC) AS rn   FROM product_data,         generate_series(1, quantity) ),  -- \u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0435\u0434\u0438\u043d\u0438\u0446 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u043f\u043b\u0430\u0447\u0435\u043d\u044b units_to_pay AS (   SELECT     order_id,     promo_type,     COUNT(*) AS total_units,     CASE       WHEN promo_type = '2=1' THEN FLOOR(COUNT(*) \/ 2) + MOD(COUNT(*), 2)       WHEN promo_type = '3=1' THEN FLOOR(COUNT(*) \/ 3) + MOD(COUNT(*), 3)       ELSE COUNT(*)     END AS units_to_pay   FROM expanded_units   GROUP BY order_id, promo_type ),  -- \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c N \u0441\u0430\u043c\u044b\u0445 \u0434\u043e\u0440\u043e\u0433\u0438\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043a \u043e\u043f\u043b\u0430\u0442\u0435 promo_payment AS (   SELECT     e.order_id,     SUM(e.effective_price) AS promo_amount   FROM expanded_units e   JOIN (     SELECT       order_id,       promo_type,       units_to_pay     FROM units_to_pay   ) u ON e.order_id = u.order_id AND e.promo_type = u.promo_type   WHERE e.rn &lt;= u.units_to_pay   GROUP BY e.order_id )  SELECT   order_id,   promo_amount FROM promo_payment ORDER BY order_id;<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/summary>\n<div class=\"spoiler__content\">\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">order_id<\/p>\n<\/th>\n<th>\n<p align=\"left\">promo_amount<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">500.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">720.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">640.00<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<\/details>\n<h4>\u0428\u0430\u0433 4. \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0441\u0443\u043c\u043c\u044b \u0438 \u0441\u0443\u043c\u043c\u044b \u043f\u043e \u0430\u043a\u0446\u0438\u0438<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043b\u0438 \u0441\u0443\u043c\u043c\u0443 \u043f\u043e \u0442\u043e\u0432\u0430\u0440\u0430\u043c \u0431\u0435\u0437 \u0430\u043a\u0446\u0438\u0438 \u043d\u0430 \u0448\u0430\u0433\u0435 2 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u0440\u0435\u0434\u0438 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043d\u0430 \u0448\u0430\u0433\u0435 3, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432 \u0435\u0434\u0438\u043d\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0439 \u0441\u0443\u043c\u043c\u044b \u0437\u0430\u043a\u0430\u0437\u0430. \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0448\u0438\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c.<\/p>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0440\u0430\u0441\u0447\u0451\u0442\u0443, \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430 \u043f\u043e \u0437\u0430\u043a\u0430\u0437\u0443 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>\u0421\u0443\u043c\u043c\u0443 \u0432\u0441\u0435\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0431\u0435\u0437 \u0430\u043a\u0446\u0438\u0438 \u2013 <code>main_sum<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0434\u043d\u0443 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u0440\u0435\u0434\u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u0432, \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0432 \u0430\u043a\u0446\u0438\u0438 \u2013 <code>promo_amount<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0418\u0418 \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u0448\u0430\u0433\u0435:<\/p>\n<blockquote>\n<p>\u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u0434\u0432\u0430 CTE: <code>base_sum<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <code>order_id<\/code> \u0438 \u0441\u0443\u043c\u043c\u0443 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432, \u0438 <code>promo_payment<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <code>order_id<\/code> \u0438 \u0441\u0443\u043c\u043c\u0443 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043a \u043e\u043f\u043b\u0430\u0442\u0435. \u041c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0438\u0445 \u043f\u043e <code>order_id<\/code> \u0438 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u0437\u0430\u043a\u0430\u0437\u0430 \u043a\u0430\u043a \u0441\u0443\u043c\u043c\u0443 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0438 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445. \u0412\u0435\u0440\u043d\u0438 \u043f\u043e\u043b\u043d\u044b\u0439 \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<\/blockquote>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0438\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0441\u0443\u043c\u043c\u0430 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0443\u043c\u043c\u0430 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u043f\u043b\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u043e\u0432\u0430\u0440\u044b, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0443\u043c\u043c\u044b \u043f\u043e \u0430\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 <code>NULL<\/code>, \u0438 \u0435\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 0 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>COALESCE<\/code>.<\/p>\n<p>\u041d\u0430 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043c\u044b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0434\u0432\u0430 \u0440\u0430\u043d\u0435\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 CTE \u2013 \u0441 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0441\u0443\u043c\u043c\u043e\u0439 (<code>base_sum<\/code>) \u0438 \u0441 \u0441\u0443\u043c\u043c\u043e\u0439 \u043e\u043f\u043b\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 (<code>promo_payment<\/code>) \u2013 \u043f\u043e \u043f\u043e\u043b\u044e <code>order_id<\/code>. \u041e\u0441\u043d\u043e\u0432\u0443 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 <code>base_sum<\/code>, \u0442\u0430\u043a \u043a\u0430\u043a \u0437\u0430\u043a\u0430\u0437 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u0442\u043e\u0432\u0430\u0440\u0430.<\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u044d\u0442\u043e\u0433\u043e \u0448\u0430\u0433\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043a\u0430\u0437\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0438\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0441\u0443\u043c\u043c\u0430 \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0432\u0441\u0435\u0445 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u0430\u0432\u0438\u043b \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0430\u043a\u0446\u0438\u0439.<\/p>\n<pre><code class=\"sql\">WITH product_data AS (   SELECT     oi.order_id,     oi.product_id,     COALESCE(pp.promo_price, pr.price) AS effective_price,     COALESCE(promo.promo_type, upd.promo_type) AS promo_type,     oi.quantity   FROM order_items oi   JOIN product_prices pr ON oi.product_id = pr.product_id   LEFT JOIN promo_prices pp ON oi.product_id = pp.product_id   LEFT JOIN product_promotions promo ON oi.product_id = promo.product_id   LEFT JOIN product_updates upd ON oi.product_id = upd.product_id   WHERE oi.quantity &gt; 0 ),  -- \u0421\u0447\u0438\u0442\u0430\u0435\u043c \u0441\u0443\u043c\u043c\u0443 \u043f\u043e \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u0442\u043e\u0432\u0430\u0440\u0430\u043c (\u0431\u0435\u0437 \u0430\u043a\u0446\u0438\u0438) normal_sum AS (   SELECT     order_id,     SUM(effective_price * quantity) AS normal_amount   FROM product_data   WHERE promo_type IS NULL   GROUP BY order_id ),  -- \u0420\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0436\u0434\u0443\u044e \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0442\u043e\u0432\u0430\u0440\u0430 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 expanded_units AS (   SELECT     order_id,     promo_type,     effective_price,     ROW_NUMBER() OVER (PARTITION BY order_id, promo_type ORDER BY effective_price DESC) AS rn   FROM product_data,        generate_series(1, quantity)   WHERE promo_type IS NOT NULL ),  -- \u0421\u0447\u0438\u0442\u0430\u0435\u043c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0435\u0434\u0438\u043d\u0438\u0446 \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u043b\u0430\u0442\u0438\u0442\u044c \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0430\u043a\u0446\u0438\u0438 \u0438 \u0437\u0430\u043a\u0430\u0437\u0443 units_to_pay AS (   SELECT     order_id,     promo_type,     COUNT(*) AS total_units,     CASE       WHEN promo_type = '2=1' THEN FLOOR(COUNT(*) \/ 2) + MOD(COUNT(*), 2)       WHEN promo_type = '3=1' THEN FLOOR(COUNT(*) \/ 3) + MOD(COUNT(*), 3)       ELSE COUNT(*)     END AS units_to_pay   FROM expanded_units   GROUP BY order_id, promo_type ),  -- \u0421\u0447\u0438\u0442\u0430\u0435\u043c \u0441\u0443\u043c\u043c\u0443 \u043a \u043e\u043f\u043b\u0430\u0442\u0435 \u0437\u0430 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u043e\u0432\u0430\u0440\u044b: \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0430\u043c\u044b\u0435 \u0434\u043e\u0440\u043e\u0433\u0438\u0435 N \u0435\u0434\u0438\u043d\u0438\u0446 promo_payment AS (   SELECT     e.order_id,     SUM(e.effective_price) AS promo_amount   FROM expanded_units e   JOIN units_to_pay u ON e.order_id = u.order_id AND e.promo_type = u.promo_type   WHERE e.rn &lt;= u.units_to_pay   GROUP BY e.order_id )  -- \u0418\u0442\u043e\u0433: \u0441\u0443\u043c\u043c\u0430 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 + \u0441\u0443\u043c\u043c\u0430 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 SELECT   COALESCE(n.order_id, p.order_id) AS order_id,   COALESCE(n.normal_amount, 0) + COALESCE(p.promo_amount, 0) AS total_order_amount FROM normal_sum n FULL OUTER JOIN promo_payment p ON n.order_id = p.order_id ORDER BY order_id;<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/summary>\n<div class=\"spoiler__content\">\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">order_id<\/p>\n<\/th>\n<th>\n<p align=\"left\">total_order_amount<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">1450.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">1240.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">1540.00<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<\/details>\n<h3>\u041f\u043e\u0434\u0432\u0435\u0434\u0435\u043c \u0438\u0442\u043e\u0433\u0438<\/h3>\n<p>\u0421\u0430\u043c\u044b\u0439 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u0432\u044b\u043d\u0435\u0441\u043b\u0430 \u0438\u0437 \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438, \u0447\u0442\u043e \u0418\u0418 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0432 \u0440\u0430\u0431\u043e\u0442\u0435, \u043d\u0435 \u0434\u0435\u043b\u0430\u044f \u0435\u0451 \u0437\u0430 \u0442\u0435\u0431\u044f. \u0412\u0430\u0436\u043d\u043e \u0432\u043b\u0430\u0434\u0435\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u043c, \u043f\u0440\u043e\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u0430\u0436\u043d\u043e, \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0430\u043b\u0430\u0441\u044c \u043f\u043e \u0448\u0430\u0433\u0430\u043c. \u041a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u044d\u0442\u0430\u043f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e, \u0447\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u043b\u043e \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0438 \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430. \u0415\u0441\u043b\u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u0438 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0431\u0435\u0437\u0434\u0443\u043c\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0432\u0441\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0441\u0440\u0430\u0437\u0443 \u0438 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0418\u0418, \u043d\u0430 \u044d\u0442\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0441\u0438\u043b. \u0418 \u043d\u0435 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043f\u0440\u0438\u0439\u0442\u0438 \u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u043c\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 \u0431\u0435\u0437 \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0430\u0432\u043e\u043a.<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0418\u0418 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u2013 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0441\u0432\u043e\u0438\u0445 \u043a\u043e\u043c\u043f\u0435\u0442\u0435\u043d\u0446\u0438\u0439, \u0430 \u043d\u0435 \u0443\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0438\u0445 \u0438\u043b\u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c. \u0414\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u043a\u0430\u043a \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0418\u0418 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043a\u0430\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0441 \u0418\u0418 \u0432\u044b \u0431\u044b \u0445\u043e\u0442\u0435\u043b\u0438 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 <a href=\"https:\/\/www.db-fiddle.com\/\" rel=\"noopener noreferrer nofollow\">https:\/\/www.db-fiddle.com\/<\/a>.<\/p>\n<div class=\"embed_link\">\n<div class=\"embed__thumb\" style=\"background-image: url(&quot;https:\/\/cdn4.cdn-telegram.org\/file\/aE7lD2wsECBlQkliRTNez67HXjZtOacouXrHKx3m_-gePEvnFW0ptxvgO1oEQiGjuPm_5qS7oMKBV1PD8l4P0K6oSuY_n8OYc4F1V9Fe5ui_9axvJTEU_EkG0ibZuMdASJFJgQ73leb8WrP4zANIdwOW-L9pfYipefqZtxwip-DEmg_mduygyFPVp6n_EoZtJSDhCmhht9InGWi_lyotIsen6YLcKuWF655kifvaXxOi5ZL4FzOiN95-UmSmDHp62GTT8KoP61_HM0IIxW9HlYEpSe5VVh3N3W7JEcHC2IU07IyBgg9rdjkBsCdA8UbV4oGBKn1V2lTydHq6RGlMuQ.jpg&quot;);\"><\/div>\n<div class=\"embed__caption\">\n<div class=\"embed__caption-title\"><span>IT Talks | \u041e\u0448\u0443\u0440\u043a\u043e\u0432\u0430 \u0422\u0430\u0442\u044c\u044f\u043d\u0430<\/span><\/div>\n<p><a href=\"https:\/\/t.me\/it_tlk\" target=\"_blank\" rel=\"noopener noreferrer nofollow\" class=\"embed__caption-host\">t.me<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/921888\/\"> https:\/\/habr.com\/ru\/articles\/921888\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0422\u0430\u0442\u044c\u044f\u043d\u0430 \u041e\u0448\u0443\u0440\u043a\u043e\u0432\u0430, \u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0438 \u0430\u0432\u0442\u043e\u0440\u00a0<a href=\"https:\/\/t.me\/it_tlk\" rel=\"noopener noreferrer nofollow\">\u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u043a\u0430\u043d\u0430\u043b\u0430 IT Talks<\/a>. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0430 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0441\u0430\u043c\u043e\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0438 \u0445\u0430\u0439\u043f\u043e\u0432\u044b\u0445 \u0442\u0435\u043c. \u0421\u043a\u0430\u0436\u0443 \u0447\u0435\u0441\u0442\u043d\u043e, \u044f \u043d\u0435 \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0441\u044c \u043c\u043d\u0435\u043d\u0438\u044f, \u0447\u0442\u043e \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442 \u0437\u0430\u043c\u0435\u043d\u0438\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0438 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<p>\u041c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0446\u0438\u0442\u0430\u0442\u0430: <strong>\u00ab\u0418\u0418 \u043f\u0440\u0438\u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442 \u0442\u0432\u043e\u0438 \u043a\u043e\u043c\u043f\u0435\u0442\u0435\u043d\u0446\u0438\u0438\u00bb<\/strong>. \u0415\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e. \u0422\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0442\u0435\u0431\u0435 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435, \u0430 \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0451 \u0437\u0430 \u0442\u0435\u0431\u044f.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u0440\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0434\u043b\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0430 \u2013 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0441\u0440\u0435\u0434\u043d\u0435\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0418\u0418 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u044d\u0442\u0430\u043f\u0430\u0445.<\/p>\n<blockquote>\n<p>\u0410 \u0435\u0449\u0451\u00a0<a href=\"https:\/\/t.me\/ittalks_aibot\" rel=\"noopener noreferrer nofollow\">\u0443 \u043c\u0435\u043d\u044f \u0432 \u0431\u043e\u0442\u0435<\/a>\u00a0\u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c <strong>\u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0433\u0430\u0439\u0434,<\/strong> \u0433\u0434\u0435 \u0442\u044b \u043d\u0430\u0439\u0434\u0435\u0448\u044c \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043f\u044f\u0442\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c \u043d\u0430 PlantUML \u0432 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u0435\u0439\u0441\u0430\u0445 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c.<\/p>\n<\/blockquote>\n<h3>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h3>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0437\u0430\u043a\u0430\u0437\u0430\u043c\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0432 \u043d\u0435\u043a\u043e\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u0412 \u0437\u0430\u043a\u0430\u0437\u0430\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u044b, \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0446\u0435\u043d\u0430, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0443\u0447\u0430\u0441\u0442\u0438\u044f \u0432 \u0430\u043a\u0446\u0438\u0438. \u0410\u043a\u0446\u0438\u0438 \u0431\u044b\u0432\u0430\u044e\u0442 \u0434\u0432\u0443\u0445 \u0432\u0438\u0434\u043e\u0432: 2=1 \u0438\u043b\u0438 3=1 \u2013 \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u043a\u0443\u043f\u043a\u0430 \u0434\u0432\u0443\u0445 \u0438\u043b\u0438 \u0442\u0440\u0451\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043f\u043e \u0446\u0435\u043d\u0435 \u043e\u0434\u043d\u043e\u0433\u043e. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443, \u0433\u0434\u0435 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043a\u0430\u0437\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438 \u0438\u0445 \u0438\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0441\u0443\u043c\u043c\u0430. \u041d\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u0437\u0430\u043a\u0430\u0437\u0430\u0445 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u043e\u0432\u0430\u0440\u044b, \u0438\u0445 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438:<\/p>\n<ul>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435 \u0435\u0441\u0442\u044c \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u044b, \u0442\u043e \u0438\u0445 \u0441\u0443\u043c\u043c\u044b \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0439 \u0441\u0443\u043c\u043c\u0435 \u0437\u0430\u043a\u0430\u0437\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043a \u0441\u0443\u043c\u043c\u0435 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430 \u0441\u0440\u0435\u0434\u0438 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043a\u0430\u0437\u0430 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0430\u043a\u0446\u0438\u0438 2=1 \u0438\u043b\u0438 3=1.<\/p>\n<\/li>\n<li>\n<p>\u0426\u0435\u043d\u044b \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0434\u0432\u0443\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445: \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0446\u0435\u043d\u0430 \u0438 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0446\u0435\u043d\u0430. \u0415\u0441\u043b\u0438 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0446\u0435\u043d\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u0437\u043d\u0430\u043a \u0430\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0437\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0441 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u043f\u043e \u0437\u0430\u044f\u0432\u043a\u0430\u043c \u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\u043e\u043c \u043f\u043e \u0446\u0435\u043d\u0435 \u0441\u0440\u0435\u0434\u0438 \u0442\u0435\u0445, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0430 \u0430\u043a\u0446\u0438\u044f. \u041f\u043b\u044e\u0441 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445, \u0447\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438. \u0410 \u0442\u0430\u043a\u0436\u0435 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043f\u043e \u0430\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e, \u0447\u0442\u043e \u0442\u043e\u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0447\u0435\u0441\u0442\u044c \u043f\u0440\u0438 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0435.<\/p>\n<h3>\u041f\u043b\u0430\u043d \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u0431\u0435\u0437 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u0442\u0441\u044f. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0418\u0418 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b \u0434\u043b\u044f \u0442\u0435\u0431\u044f \u043f\u0440\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0437\u0430\u0434\u0430\u0447. \u041e\u043a\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438 \u2013 \u043c\u043d\u043e\u0433\u043e\u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u0434\u0430\u0447 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438. \u041d\u043e \u043a \u044d\u0442\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c \u0438\u043d\u043e\u0433\u0434\u0430 \u0441\u043b\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0439\u0442\u0438 \u0441\u0430\u043c\u043e\u043c\u0443, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0441\u0440\u0430\u0437\u0443.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0441\u0440\u0430\u0437\u0443 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0418\u0418. \u042f \u043e\u043f\u0438\u0441\u0430\u043b\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0441\u0432\u044f\u0437\u0438, \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u0440\u0435\u0448\u0430\u0435\u043c\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0443 \u043c\u0435\u043d\u044f \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c.<\/p>\n<p>\u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0418\u0418 \u044f \u0431\u044b \u043d\u0430\u0437\u0432\u0430\u043b\u0430 \u043d\u0435\u0443\u043c\u0435\u043d\u0438\u0435 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0438\u0441\u043a\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u0438, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u0440\u0435\u0448\u0438\u0442\u044c \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c. \u0414\u0430\u043b\u0435\u0435 \u044f \u0440\u0430\u0437\u0431\u0438\u043b\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438:<\/p>\n<ul>\n<li>\n<p>\u0421\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0437\u0430\u043a\u0430\u0437\u043e\u0432 \u0441 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430\u043c\u0438, \u0446\u0435\u043d\u0430\u043c\u0438 \u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u043c \u0430\u043a\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0418\u0418:<\/p>\n<ul>\n<li>\n<p>\u0421\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u0434\u043b\u044f \u043d\u0435\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0439\u0442\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0446\u0435\u043d\u0443 \u0441\u0440\u0435\u0434\u0438 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043b\u043e\u0436\u0438\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0441\u0443\u043c\u043c\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0432 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0447\u0430\u0441\u0442\u0438.<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u0438\u043f\u0442\u044b \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c  PostgreSQL<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">-- \u0417\u0430\u043a\u0430\u0437\u044b \u0438 \u0442\u043e\u0432\u0430\u0440\u044b CREATE TABLE order_items (     order_id INT,     product_id INT,     quantity INT );  -- \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0446\u0435\u043d\u044b CREATE TABLE product_prices (     product_id INT,     price DECIMAL(10, 2) );  -- \u0410\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0446\u0435\u043d\u044b CREATE TABLE promo_prices (     product_id INT,     promo_price DECIMAL(10, 2) );  -- \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u0430\u043a\u0446\u0438\u0438 CREATE TABLE product_promotions (     product_id INT,     promo_type VARCHAR(10)  -- \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, '2=1', '3=1' );  -- \u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u0430\u043a\u0446\u0438\u0438 (\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f) CREATE TABLE product_updates (     product_id INT,     promo_type VARCHAR(10) );  -- \u0417\u0430\u043a\u0430\u0437\u044b \u0438 \u0442\u043e\u0432\u0430\u0440\u044b INSERT INTO order_items VALUES (1, 101, 1), (1, 102, 2), (1, 103, 1), (1, 104, 2), (1, 105, 3), (2, 201, 2), (2, 202, 1), (2, 203, 3), (2, 204, 1), (2, 205, 2), (3, 301, 2), (3, 302, 1), (3, 303, 1), (3, 304, 2), (3, 305, 2);  -- \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0446\u0435\u043d\u044b \u0442\u043e\u0432\u0430\u0440\u043e\u0432 INSERT INTO product_prices VALUES (101, 100.00), (102, 200.00), (103, 300.00), (104, 250.00), (105, 150.00), (201, 120.00), (202, 180.00), (203, 260.00), (204, 230.00), (205, 140.00), (301, 160.00), (302, 180.00), (303, 300.00), (304, 350.00), (305, 200.00);  -- \u0410\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0446\u0435\u043d\u044b (\u0435\u0441\u0442\u044c \u043d\u0435 \u0443 \u0432\u0441\u0435\u0445) INSERT INTO promo_prices VALUES (103, 280.00), (104, 220.00), (203, 240.00), (304, 320.00);  -- \u041f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0430\u043a\u0446\u0438\u0439 \u0438\u0437 product_promotions (\u0442\u043e\u043b\u044c\u043a\u043e 2=1 \u0434\u043b\u044f \u0437\u0430\u043a\u0430\u0437\u043e\u0432 1 \u0438 3) INSERT INTO product_promotions VALUES (103, '2=1'), (104, '2=1'), (303, '2=1');  -- \u041f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0430\u043a\u0446\u0438\u0439 \u0438\u0437 product_updates (\u0442\u043e\u043b\u044c\u043a\u043e 3=1 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435 2 \u0438 2=1 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435 3) INSERT INTO product_updates VALUES (202, '3=1'), (203, '3=1'), (204, '3=1'), (304, '2=1');<\/code><\/pre>\n<\/div>\n<\/details>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<h4>\u0428\u0430\u0433 1. \u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438<\/h4>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0438 \u0441\u0430\u043c\u044b\u0439 \u0432\u0430\u0436\u043d\u044b\u0439 \u0448\u0430\u0433 \u2013  \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0443\u044e \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438 \u043e\u0431\u043e\u0433\u0430\u0449\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c\u0438 \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e, \u0447\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0446\u0435\u043d\u0435 \u0442\u043e\u0432\u0430\u0440\u0430 \u043c\u043e\u0433\u043b\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445: \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 (<code>product_prices<\/code>) \u0438 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u043e\u0439 (<code>promo_prices<\/code>). \u0415\u0441\u043b\u0438 \u0434\u043b\u044f \u0442\u043e\u0432\u0430\u0440\u0430 \u0435\u0441\u0442\u044c \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0446\u0435\u043d\u0430, \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0440\u0430\u0441\u0447\u0451\u0442\u0435, \u0430 \u043d\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>COALESCE<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u043e\u0435 \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2013 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 <code>promo_price<\/code>, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0435\u0441\u0442\u044c, \u0430 \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u2013 \u043e\u0431\u044b\u0447\u043d\u0443\u044e <code>price<\/code>.<\/p>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0438 \u0441 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u043c \u0443\u0447\u0430\u0441\u0442\u0438\u044f \u0442\u043e\u0432\u0430\u0440\u0430 \u0432 \u0430\u043a\u0446\u0438\u0438. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0430\u043d \u043b\u0438\u0431\u043e \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <code>product_promotions<\/code>, \u043b\u0438\u0431\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 <code>product_updates<\/code>, \u0447\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u043c\u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u0427\u0442\u043e\u0431\u044b \u0443\u0447\u0435\u0441\u0442\u044c \u044d\u0442\u043e, \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>COALESCE<\/code>, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044f \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 (<code>product_promotions<\/code>), \u0438 \u043f\u0440\u0438 \u0435\u0433\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u2013 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e (<code>product_updates<\/code>).<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0430\u044f \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435: ID \u0437\u0430\u043a\u0430\u0437\u0430, ID \u0442\u043e\u0432\u0430\u0440\u0430, \u0446\u0435\u043d\u0443 \u0442\u043e\u0432\u0430\u0440\u0430 \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0439 \u0430\u043a\u0446\u0438\u0438, \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0443\u0447\u0430\u0441\u0442\u0438\u044f \u0432 \u0430\u043a\u0446\u0438\u0438 (<code>promo_type<\/code>), \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0435\u0434\u0438\u043d\u0438\u0446 \u0442\u043e\u0432\u0430\u0440\u0430 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435. \u0418\u043c\u0435\u043d\u043d\u043e \u043d\u0430 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u043e\u0438\u0442\u044c\u0441\u044f \u0432\u0441\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u2013 \u043a\u0430\u043a \u0434\u043b\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0438\u0437 \u0440\u0430\u0441\u0447\u0451\u0442\u0430, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445 \u043e\u0431\u0440\u0430\u0442\u043d\u043e (\u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438).<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u044d\u0442\u043e\u0442 \u0448\u0430\u0433 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c. \u041e\u043d \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u043b \u0435\u0434\u0438\u043d\u044b\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0440\u0430\u0441\u0447\u0451\u0442\u043e\u0432. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0447\u0430\u0441\u0442\u044f\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0430\u0441\u0447\u0451\u0442 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u043c \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u043c.<\/p>\n<pre><code class=\"sql\">WITH product_data AS (   SELECT     oi.order_id,     oi.product_id,     COALESCE(pp.promo_price, pr.price) AS effective_price,     COALESCE(promo.promo_type, upd.promo_type) AS promo_type,     oi.quantity   FROM order_items oi   JOIN product_prices pr ON oi.product_id = pr.product_id   LEFT JOIN promo_prices pp ON oi.product_id = pp.product_id   LEFT JOIN product_promotions promo ON oi.product_id = promo.product_id   LEFT JOIN product_updates upd ON oi.product_id = upd.product_id ) SELECT   order_id,   product_id,   effective_price,   promo_type,   quantity FROM product_data ORDER BY order_id, product_id;<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/summary>\n<div class=\"spoiler__content\">\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">order_id<\/p>\n<\/th>\n<th>\n<p align=\"left\">product_id<\/p>\n<\/th>\n<th>\n<p align=\"left\">effective_price<\/p>\n<\/th>\n<th>\n<p align=\"left\">promo_type<\/p>\n<\/th>\n<th>\n<p align=\"left\">quantity<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">101<\/p>\n<\/td>\n<td>\n<p align=\"left\">100.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">102<\/p>\n<\/td>\n<td>\n<p align=\"left\">200.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">103<\/p>\n<\/td>\n<td>\n<p align=\"left\">280.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">2=1<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">104<\/p>\n<\/td>\n<td>\n<p align=\"left\">220.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">2=1<\/p>\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">105<\/p>\n<\/td>\n<td>\n<p align=\"left\">150.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">201<\/p>\n<\/td>\n<td>\n<p align=\"left\">120.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">202<\/p>\n<\/td>\n<td>\n<p align=\"left\">180.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">3=1<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">203<\/p>\n<\/td>\n<td>\n<p align=\"left\">240.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">3=1<\/p>\n<\/td>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">204<\/p>\n<\/td>\n<td>\n<p align=\"left\">230.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">3=1<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">205<\/p>\n<\/td>\n<td>\n<p align=\"left\">140.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">301<\/p>\n<\/td>\n<td>\n<p align=\"left\">160.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">302<\/p>\n<\/td>\n<td>\n<p align=\"left\">180.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">303<\/p>\n<\/td>\n<td>\n<p align=\"left\">300.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">2=1<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">304<\/p>\n<\/td>\n<td>\n<p align=\"left\">320.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">2=1<\/p>\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">305<\/p>\n<\/td>\n<td>\n<p align=\"left\">200.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<\/details>\n<h4>\u0428\u0430\u0433 2. \u0420\u0430\u0441\u0447\u0451\u0442 \u0441\u0443\u043c\u043c\u044b \u0437\u0430\u043a\u0430\u0437\u0430 \u0431\u0435\u0437 \u0443\u0447\u0451\u0442\u0430 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u043f\u043e\u043b\u043d\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0432\u0441\u0435\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0441 \u0446\u0435\u043d\u0430\u043c\u0438 \u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c\u0438 \u0430\u043a\u0446\u0438\u0439, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0441\u0442\u0430\u043b\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u0435\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0430\u043a\u0446\u0438\u044f\u0445. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0443 \u0447\u0430\u0441\u0442\u044c \u0441\u0443\u043c\u043c\u044b \u0437\u0430\u043a\u0430\u0437\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0441\u0443\u043c\u043c \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0431\u0435\u0437 \u0430\u043a\u0446\u0438\u0438. \u0421 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u044d\u0442\u0430\u043f\u0430 \u044f \u043e\u0431\u0440\u0430\u0449\u0430\u043b\u0430\u0441\u044c \u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u043a \u0418\u0418, \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044f, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430:<\/p>\n<blockquote>\n<p> \u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 <code>product_data<\/code> \u0441 \u043f\u043e\u043b\u044f\u043c\u0438: <code>order_id<\/code>, <code>product_id<\/code>, <code>effective_price<\/code>, <code>promo_type<\/code>, <code>quantity<\/code>. \u041c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043a\u0430\u0437\u0430 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0431\u0435\u0437 \u0430\u043a\u0446\u0438\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0435\u0445, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 <code>promo_type IS NULL<\/code>. \u0412\u0435\u0440\u043d\u0438 SQL-\u0437\u0430\u043f\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>order_id<\/code> \u0438 \u0441\u0443\u043c\u043c\u0443 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432, \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 (<code>quantity * effective_price<\/code>). \u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430 \u0437\u0430\u043a\u0430\u0437.   <\/p>\n<\/blockquote>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043d\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u043b\u043e\u0433\u0438\u043a\u0443 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438, \u0435\u0441\u043b\u0438 \u0442\u043e\u0432\u0430\u0440 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0430\u043a\u0446\u0438\u0438 \u00ab2=1\u00bb \u0438\u043b\u0438 \u00ab3=1\u00bb, \u0442\u043e \u043e\u043d \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u0437\u0430\u043a\u0430\u0437\u0430 \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c (\u0442.\u0435. \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435 <code>\u0446\u0435\u043d\u0430 \u00d7 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e<\/code>). \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043e\u0441\u043e\u0431\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u043e\u0437\u0436\u0435 (\u043d\u0430 \u0448\u0430\u0433\u0435 3), \u0430 \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0442\u043e\u0432\u0430\u0440\u044b \u0438\u0437 \u0440\u0430\u0441\u0447\u0451\u0442\u0430.<\/p>\n<p>\u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e: \u0441\u0442\u0440\u043e\u043a\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e <code>promo_type IS NULL<\/code>, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0442\u043e\u0432\u0430\u0440 \u043d\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0430\u043a\u0446\u0438\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0440\u0430\u043d\u0435\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 CTE (<code>product_data<\/code>), \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043d\u0443\u0436\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0442\u043e\u0432\u0430\u0440\u0443: ID \u0437\u0430\u043a\u0430\u0437\u0430, \u0446\u0435\u043d\u0430, \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0430\u043a\u0446\u0438\u0438 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e.<\/p>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0435\u0439 \u044d\u0442\u043e\u043c\u0443 \u0444\u0438\u043b\u044c\u0442\u0440\u0443, \u043c\u044b \u043f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0430\u0435\u043c <code>effective_price<\/code> \u043d\u0430 <code>quantity<\/code> \u2013 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u0442\u043e\u0432\u0430\u0440\u0430 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435. \u0417\u0430\u0442\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e <code>order_id<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0437\u0430\u043a\u0430\u0437\u0443.<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u0448\u0430\u0433\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u0431\u0430\u0437\u043e\u0432\u0430\u044f \u0441\u0443\u043c\u043c\u0430 \u0437\u0430\u043a\u0430\u0437\u0430 \u2013 \u0431\u0435\u0437 \u0443\u0447\u0451\u0442\u0430 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043f\u043e\u0437\u0438\u0446\u0438\u0439. \u042d\u0442\u043e \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u00ab\u0447\u0438\u0441\u0442\u0430\u044f\u00bb \u0441\u0443\u043c\u043c\u0430, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u043f\u043e\u0437\u0436\u0435 \u043f\u0440\u0438\u0431\u0430\u0432\u0438\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432 \u0437\u0430\u043a\u0430\u0437\u0435 \u0435\u0441\u0442\u044c \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u043e\u0432\u0430\u0440\u044b.<\/p>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0448\u0430\u0433\u0430 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-464615","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/464615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=464615"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/464615\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=464615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=464615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=464615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}