订单基础表
PO_HEAD_TBL
字段
PO_NO SUM_PRICE
0001 20.55
订单详细信息表
PO_LINE_TBL
ID PO_NO UNIT_PRICE
1 0001 10.55
2 0001 5.0
3 0001 5.0
oracle数据库
两个表的关联字段是PO_NO
订单基础表中的 SUM_PRICE 字段 ......
我要创建一个临时表保存数据
方法一:
declare @sql varchar(1000)
set @sql = 'select identity(int,1,1) as tbId,* into #tb1 from table1 where 1=0'
exec(@sql)
select * from #tb1
drop table #tb1
方法二:
select identity(int,1,1) as tbId,* into #tb2 from table1 where 1=0
select * from #tb2
drop t ......
SQL code:
create table order1 (时间 varchar(30) primary key not NULL ,阻值 numeric(5,3) , 功率 numeric(5,3))
INSERT INTO order1(时间,阻值,功率 )VALUES (convert(varchar,getdate(),21),123,333)
本人想在该表的时间字段上加一个聚集索引,以年月日小时为单位,怎么写?
SQL code:
create table ......
表t1、t2相同
当t1中,A、B两个字段相同时,将字段C求和后插入到t2中
在t1中:
A B C
a1 b1 1
a1 b1 2
a1 b1 3
a2 b2 1
a2 b2 2
需要在t2中得到
a1 b1 6
a2 b2 3
SQL code:
insert t2
selct A,B,sum(C) C from t1 group by A,B
SQL code:
insert c select a,b,isnull(c, ......
现有字段:
id,fromplace,toplace,scount,logyear,logmonth
备注:
fromplace:出发地
toplace:目的地
scount:搜索次数
logyear:记录年
logmonth:记录月
现在想用一条SQL语句查询每年每个月中,搜索次数在前20的记录
SQL code:
select *
from tb t
where id
in (select top 20 id from tb where t.log ......
现有字段:
id,stype,fromplace,toplace,scount,logyear,logmonth
备注:
stype:搜索类型
fromplace:出发地
toplace:目的地
scount:搜索次数
logyear:记录年
logmonth:记录月
现在想用一条SQL语句根据搜索类型查询每月中,搜索次数在前20的记录
刚刚那个帖子修改过,但是很多人都只看最先的问题,没有注意到 ......