sql精确查询语句(**L的查询语句)
本文目录
**L的查询语句
1、统计2008年度销售总金额:
select sum(b.单价*a.数量) from p_order a,product b where a.产品ID=b.产品ID and to_char(a.订货日期,’yyyy’)=’2008’;
统计2008年度某类商品的销售总金额:
select sum(b.单价*a.数量) from p_order a,product b where a.产品ID=b.产品ID and to_char(a.订货日期,’yyyy’)=’2008’ and 产品ID=某类;
统计2008年度某大类商品的销售总金额:
select sum(b.单价*a.数量) from p_order a,product b where a.产品ID=b.产品ID and to_char(a.订货日期,’yyyy’)=’2008’ and 产品ID=大某类;
利用Sql语句进行精确查询
我不懂php语法,但大致是下面的意思,你自己参考一下:
$sql="SELECT s.* FROM ".tname(’space’)." s LEFT JOIN ".tname(’spacefield’)." sp ON sp.uid=s.uid LEFT JOIN ".tname(’spaceinfo’)." si ON si.uid=sp.uid WHERE 1 = 1 "
if($_GET}%’" }
if($_GET}’)" }
if($_GET}’)" }
sql 查询语句
1,.select a.G_applydate from g_cardapply a join g_cardapplydetail b on a.申请单号=b.申请单号 where b.G_idcard varchar = ’610123123123132123’;
2.select G_idcard ,count(*) as geshu from _cardapplydetail group by G_idcard;
3.update a set a. G_state varchar = ’07’
from g_cardapply a join g_cardapplydetail b on a.申请单号=b.申请单号
where b. G_idcard = ’610123123123132123’ ;
update g_cardapplydetail set G_state varchar = ’07’
where G_idcard = ’610123123123132123’ ;
4.delete g_cardapplydetail where G_name like ’李%’;
**L 查询语句
(1)select 学号,姓名,成绩 from table where 课程号=’001’ and 成绩《60
求sql查询语句
declare @sql varchar(max)
declare @i int
set @i = 1
set @sql = ’select * from 表名 where ID = ’ + convert(varchar, @i)
while (select ID号 from 表名 where ID = @i) is not null
begin
set @sql = @sql + ’ union all ’
set @i = (select ID号 from 表名 where ID = @i)
set @sql = @sql + ’select * from 表名 where ID = ’ + convert(varchar, @i)
end
exec (@sql)
已经测试过了,正确。
如果你输入的条件是ID=2和话,把里面的set @i = 1改成set @i = 2就行。
也可以做一个存储过程,把@i作为一个变量输入,如果需要的话我帮你加。
算了,我把我创建的测试表和整个过程都发出来吧……
--创建表
create table Circle
(
ID int,
名字 varchar(10),
ID号 int
)
--插入数据
insert into Circle values (1, ’a’, 52)
insert into Circle values (2, ’a’, 53)
insert into Circle values (3, ’a’, 54)
insert into Circle values (4, ’a’, null)
insert into Circle values (52, ’a’, 158)
insert into Circle values (53, ’a’, 159)
insert into Circle values (54, ’a’, null)
insert into Circle values (158, ’a’, 542)
insert into Circle values (159, ’a’, null)
insert into Circle values (542, ’a’, null)
select * from Circle
--创建存储过程
create procedure procCircle @i int
as
begin
declare @sql varchar(max)
set @sql = ’select * from Circle where ID = ’ + convert(varchar, @i)
while (select ID号 from Circle where ID = @i) is not null
begin
set @sql = @sql + ’ union all ’
set @i = (select ID号 from Circle where ID = @i)
set @sql = @sql + ’select * from Circle where ID = ’ + convert(varchar, @i)
end
exec (@sql)
end
--执行存储过程进行验证
procCircle 1
procCircle 2
procCircle 3
procCircle 4
drop procedure procCircle
更多文章:
学校网页模板html(网页模板,要求10个链接的,谁能给我一份谢谢,学校作业急急急急急急急急急急)
2026年4月7日 04:20
insert语句主键自增(sql 主键自增了 insert into语句怎么打)
2026年4月7日 04:00
八进制转十六进制怎么算(八进制转换成十六进制的算法 请举例说明)
2026年4月7日 03:40
没有密钥怎么激活windows10(台式电脑没有密钥怎么永久激活windows10)
2026年4月7日 03:20
html基础语句(HTML/css 的语句,求解释:“div#maincontent button“ )
2026年4月7日 02:00
shell脚本批量添加10个用户(一次性Linux创建1000个用户 user 初始密码都为123456 shell脚本怎么写)
2026年4月7日 01:40
fedora是linux社区发行版吗(fedora linux和linux有什么区别)
2026年4月7日 01:20





