select * from tb_log where 员工='A' union all select * from tb_log where 员工 in ('B','C') and 日期>='2013/01/01'
SELECT * FROM TB WHERE 员工 = 'A' OR (员工 IN('B', 'C') AND [date] >= '2013-1-1')
请问1楼使用union all怎么用排序,我写的是这样的: select * from (select * from tb_weekplan where userid='54' order by time desc) union all select * from (select * from tb_weekplan where userid in (33) and time>=to_date('2013-06-01','yyyy-MM-dd') order by time desc) 但它排序时是先对第一个用户排序,然后再对第二个用户排,怎么让它完全按日期排序,而不是先排序userid 54,再排序userid 33二楼的排序是解决了,但我条件查询,使用OR用不了查询 " from tb_weekplan where" +GetWhere(nvc) + " and userid=54 or (userid in(33) and time>=to_date('2013-08-01','yyyy-MM-dd')) and userid=33 order by time descpublic string GetWhere(NameValueCollection nvc) { string where = " weekplanid<>0"; if (!string.IsNullOrEmpty(nvc["txt_time"])) { where += " and time >= to_date('" + nvc["txt_time"] + "','yyyy-MM-dd')"; } ...... return where; }
union all
select * from tb_log where 员工 in ('B','C') and 日期>='2013/01/01'
WHERE 员工 = 'A' OR (员工 IN('B', 'C') AND [date] >= '2013-1-1')
select * from (select * from tb_weekplan where userid='54' order by time desc) union all select * from (select * from tb_weekplan where userid in (33) and time>=to_date('2013-06-01','yyyy-MM-dd') order by time desc)
但它排序时是先对第一个用户排序,然后再对第二个用户排,怎么让它完全按日期排序,而不是先排序userid 54,再排序userid 33二楼的排序是解决了,但我条件查询,使用OR用不了查询
" from tb_weekplan where" +GetWhere(nvc) + " and userid=54 or (userid in(33) and time>=to_date('2013-08-01','yyyy-MM-dd')) and userid=33 order by time descpublic string GetWhere(NameValueCollection nvc)
{
string where = " weekplanid<>0";
if (!string.IsNullOrEmpty(nvc["txt_time"]))
{
where += " and time >= to_date('" + nvc["txt_time"] + "','yyyy-MM-dd')";
}
......
return where;
}