sql精确查询语句(SQL的查询语句)

本文目录
SQL的查询语句
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 查询语句
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 ’李%’;
SQL 查询语句
(1)select 学号,姓名,成绩 from table where 课程号=’001’ and 成绩《60
利用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查询语句
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

更多文章:
在from子句中可以出现(如何在from 子句中嵌套查询下面的语句在access中出错!)
2026年10月11日 05:20
countif函数统计个数怎么用(countif函数怎么用 详解Excel中countif函数的使用方法)
2026年10月11日 03:30
正则匹配数字之前的字符(正则表达式如何匹配前面是数字、中间是“/”、后面也是数字,就像2/3专业的模式)
2026年10月11日 03:00
orlnsertbootmediinselected(我电脑开机显示这个是什么意思or insert boot media in select)
2026年10月10日 23:00
display的用法(display是什么意思 详解display的含义和用法)
2026年10月10日 22:00
html全部居中代码(怎么让网页居中显示,html如何让网页居中)
2026年10月10日 21:10




