Mysql multi-subquery creation of multiple LEFTJOIN views

Source: Internet
Author: User

Create view 'v _ noprovide 'as select * FROMtb_sectionWHEREprovide = '0' create view 'v _ thismonth' AS SELECTts. userId AS id, CONCAT ('thismonth: ', SUM (ts. amount), 'yuanyuan ') AS 'thismonth' FROMtb _ section AS tsWHEREts. yearMonth = DATE_FORMAT (NOW (), '% Y % m') create view 'v _ lastmonth' AS SELECTts. userId AS id, CONCAT ('lastmonth: ', SUM (ts. amount), 'yuanyuan ') AS 'lastmonth' FROMtb _ section AS tsWHEREts. yearMonth = DATE_FORMAT (DATE_SUB (NOW (), INTERVAL 1 MONTH), '% Y % m') create view 'v _ usermanage' ASSELECTu. id AS id, u. email AS email, u. 'name' AS 'name', CONCAT (COALESCE (la. lastmonth, 'lastmonth: 0yuan '), COALESCE (th. thismonth, 'thismonth: 0yuan ') AS recent, Sum (COALESCE (B. amount, 0) AS totalBonus, Sum (COALESCE (n. amount, 0) AS unbilledFROMtb_user AS uLEFT JOIN tb_bonus AS B ON u. id = B. receiverIdLEFT JOIN v_noprovide AS n ON u. id = n. userIdLEFT JOIN v_thismonth AS th ON u. id = th. idLEFT JOIN v_lastmonth AS la ON u. id = la. idGROUP BY u. id

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.