1.Select * from mytable where datepart(year,[datecolname])=myyear and datepart(month,[datecolname])=mymonth
2.Select table1.id,table1.name,table1.account from Table1,table2 where Table1.id=table2.id
distinct一下
select distinct x.num,x.name from table1.dbf x,table2.dbf y
where x.num=y.num and x.num not in
(select num from table2.dbf where extract(year from date)=:valyear and extract
(month from date)=:valmonth group by num)
select distinct x.num,x.name from table1.dbf x,table2.dbf y
where x.num=y.num and x.num not in
(select num from table2.dbf where extract(year from date)=:valyear and extract
(month from date)=:valmonth group by num)
or
select x.num,x.name from table1.dbf x,table2.dbf y
where x.num=y.num and x.num not in
(select num from table2.dbf where extract(year from date)=:valyear and extract
(month from date)=:valmonth group by num)
group by x.num, x.name
多谢大家了,OK了,但是有又了新问题:
select x.num,x.name from table1.dbf x,table2.dbf y
where x.num=y.num and x.num not in
(select num from table2.dbf where extract(year from date)=:valyear and extract
(month from date)=:valmonth group by num)
最后得出:
num name
1 aaa
1 aaa
1 aaa
1 aaa
可是我只要一条记录呀。
请大家指教,多谢了!!!!!!!!!!!!!!!!!
第一個問題:(T_SQL)
select * from Table
where year(DateTimeField) = :MyYear and month(DateTimeField) = :MyMonth
第二個問題:(ANSI_SQL)
select a.號碼,a.名稱,b.金額
from Table1 a,Table2 b
where a.號碼 = b.號碼
group by a.號碼,a.名稱,b.金額
order by a.號碼,a.名稱,b.金額