mysql如何使用with,如何在MySQL中正确使用WITH ROLLUP?
groupbyyourColumnName1withrollup;
让我们首先创建一个表-mysql>createtableDemoTable1622
->(
|
使用WITH ROLLUP的语法如下-selectyourColumnName1,sum(yourColumnName2)fromyourTableName groupbyyourColumnName1withrollup; 让我们首先创建一个表-mysql>createtableDemoTable1622 ->( ->EmployeeCountryNamevarchar(20), ->EmployeeSalaryint ->); 使用插入命令在表中插入一些记录-mysql>insertintoDemoTable1622values('US',4500); mysql>insertintoDemoTable1622values('UK'mysql使用,1500); mysql>insertintoDemoTable1622values('AUS',1700); mysql>insertintoDemoTable1622values('UK',1900);
mysql>insertintoDemoTable1622values('US',3900); 使用select语句显示表中的所有记录-mysql>select*fromDemoTable1622; 这将产生以下输出-+---------------------+----------------+ |EmployeeCountryName|EmployeeSalary| +---------------------+----------------+ |US|4500| |UK|1500| |AUS|1700| |UK|1900| |US|3900| +---------------------+----------------+ 5rowsinset(0.00sec) 这是在MySQL中正确使用WITH ROLLUP的查询-mysql>selectEmployeeCountryName,sum(EmployeeSalary)fromDemoTable1622 ->groupbyEmployeeCountryNamewithrollup; 这将产生以下输出-+---------------------+---------------------+ |EmployeeCountryName|sum(EmployeeSalary)| +---------------------+---------------------+ |AUS|1700| |UK|3400| |US|8400| |NULL|13500| +---------------------+---------------------+ 4rowsinset(0.02sec) (编辑:天瑞地安资讯网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |


