当前位置:首页 » 编程语言 » sql编写

sql编写

发布时间: 2022-01-18 19:34:50

sql怎么写

建个视图吧,自动加一列是没法算了
create view 视图名 as select a,b,a/b as c from 表A

② SQL语句编写

多次update字段?没看懂你要问啥。

至于表A中的一条记录对应表B多条记录(取其中两个字段相乘再累加赋值给表A),我写个例子,你参考一下,不难的

updateaseta.zian=b.zian
fromtable1a
join(selectc.guanlianzian,sum(c.zian1*c.zian2)aszianfromtable2c)bwherea.guanlianzian=b.guanlianzian

③ SQL语言编写怎么编

一、
1,select * from 学生 where 学生号 in (select 学生号 from 选课)

2, select * from 学生 where 学生号 in (select 学生号 from 选课 having count(课程号)=3)
3, select 选课.学生号,学生.姓名,课程.课程名 from 选课 ,学生,课程
where 选课.学生号=学生.学生号 and 选课.课程号=课程.课程号 group by 选课.学生号 ,选课.成绩 ;
4,select a1.课程号,a1.课程名,count(*) as 选课人数 from 课程 a1,选课 a2 where a1.课程号=a2.课程号 group by a1.课程号,a1.课程名
5,select * from 课程 where 课程号 in( select 课程号 from 选课 having count(学生号)>=5);

二、
1、select b2.商品代号,b1.单价,b1.数量,b2.产地 from 商品表1 b1,商品表2 b2 where b1.商品代号 = b2.商品代号
2、select distinct 产地 from 商品表2
3、select top 1 * from 商品表1 order by 数量 desc

④ sql如何写

select a.*,b.rank
from score a, grade b
where a.degree <= b.upp
and a.degree >= b.Low

⑤ sql语句编写

select t1.*, t2.level, t3.effectivity
from 表1 t1 left join 表2 t2 on t1.groupID=t2.groupID
left join 表t3 on t1.groupID=t3.groupID
不知道表3中的groupID与表1中的groupID的关系,所以只用了left join,也可能表3需要过滤出唯一对应的groupID,但我不知道,这只能你自己进行修改了

⑥ SQL程序编写

declare @n int,@S int,@c int
select @n=0,@s=0,@c=1
while (@c<=50)
begin
if @c % 3=0
begin
set @n=@n+1
set @s=@S+@C
end
set @c=@c+1
end
select @n as [count],@s as [sum]

⑦ 用sql语言编写程序

select 学号,姓名,max(case when 课程='Basic' then 分数 end)as 'Basic',
max(case when 课程='C语言' then 分数 end)as'C语言',max(case when 课程='数据库' then 分数 end)as'数据库',max(case when 课程='JAVA' then 分数 end)as'JAVA',AVG(score)as ‘平均分’
from
(select a.学号,a.姓名,b.课程,b.分数
from table1 as a
inner join table2 as b
on a.学号=b.学号)as aa
where 学号='20110201008'
group by 学号,姓名

⑧ sql语句的编写

你把union改为union all 应该就行了。
如果不行就加一个隐含字段,编为1,2,3,然后再按照他排序。

⑨ 编写SQL语句

DECLARE @str varchar(1000)
declare @price float
declare @count int
DECLARE @idoc int;
DECLARE @doc xml;

declare cur cursor for select ID,价格 from 表1
open cur
fetch next from cur into @str,@price
while @@FETCH_STATUS<>-1
begin
set @doc=cast('<Root><item><ID>'+replace(@str,',','</ID></item><item><ID>')+'</ID></item></Root>' as xml)
EXEC sp_xml_preparedocument @Idoc OUTPUT, @doc
SELECT @count=COUNT(*) FROM OPENXML (@Idoc, '/Root/item',2)
WITH (
[ID] varchar(10)
)
update t1 set t1.价格=@price/@count from 表2 t1 inner join (SELECT ID FROM OPENXML (@Idoc, '/Root/item',2)
WITH (
[ID] varchar(10)
) ) t2 on t1.ID=t2.id
fetch next from cur into @str,@price
end
close cur
deallocate cur
总体思路:对表1各行ID进行拆分,然后分别更新表2的数据

热点内容
咖啡压缩糖 发布:2025-07-01 05:43:58 浏览:577
云搜卡源码 发布:2025-07-01 05:32:38 浏览:540
华为服务器怎么查ip 发布:2025-07-01 05:15:18 浏览:370
编译器中的数据结构 发布:2025-07-01 05:10:53 浏览:526
云服务器最先跑什么 发布:2025-07-01 05:02:39 浏览:217
微信公众平台手机上传视频 发布:2025-07-01 04:58:53 浏览:417
数控车床螺纹编程实例 发布:2025-07-01 04:46:27 浏览:424
什么是安卓品牌尖货 发布:2025-07-01 04:45:50 浏览:699
写入设备缓存 发布:2025-07-01 04:37:35 浏览:433
小鸡g4怎么连安卓 发布:2025-07-01 04:37:25 浏览:356