use tempdb; /* create table table1 ( id int not null, sine int not null ); insert into table1(id,sine) values (1,546),(2,541),(3,222);create table table2 ( id int not null, sine int not null ); insert into table2(id,sine) values (1,23),(2,546); */ select MAX(sine) as [最大值] from ( select * from table1 union all select * from table2 ) as t;
table = dataSet.Tables["table1"];
object o= table.Compute("max(sine)", "");
DataTable dt3 = table1.Copy();
dt3.Merge(table2);
object max = dt3.Select().Max(p => p["sine"]);
不过看了如梦的方法,还是Compute()醒目
use tempdb;
/*
create table table1
(
id int not null,
sine int not null
);
insert into table1(id,sine)
values
(1,546),(2,541),(3,222);create table table2
(
id int not null,
sine int not null
);
insert into table2(id,sine)
values
(1,23),(2,546);
*/
select MAX(sine) as [最大值]
from
(
select * from table1
union all
select * from table2
) as t;