SQL LEN () function, case when, how to use the aggregate function

Source: Internet
Author: User

SELECT AA. [User_id],cc.[user_name],dd. Name as DEPNAME,AA. Module_id,aa. Module_name,
SUM (case AA. Operate_type when ' 2 ' and then Operatenum END ' as ' addnum ',
SUM (case AA. Operate_type when ' 3 ' and then Operatenum END ' as ' editnum ',
SUM (case AA. Operate_type when ' 4 ' then operatenum END) as ' Delnum '
From (
SELECT A.[user_id],a.module_id,c.module_name,a.operate_type,count (1) as Operatenum from dbo. Sys_user_log as a
INNER JOIN dbo. Sys_module as C on a.module_id = c.module_id
WHERE LEN (a.module_id) = 6 and (A.operate_type = ' 2 ' or a.operate_type = ' 3 ' or a.operate_type = ' 4 ')//len () function
GROUP by A.[user_id],a.module_id,c.module_name,a.operate_type
) as AA
INNER JOIN dbo. Sys_user as CC on AA. [user_id] = cc.[user_id]
INNER JOIN dbo. Sys_depinfo as DD on CC. depinfo_id = dd. Id
GROUP by AA. [User_id],cc.[user_name],dd. Name,aa. Module_id,aa. Module_name
ORDER by AA. [User_id],aa. module_id

SQL LEN () function, case when, how to use the aggregate function

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.