谁来帮我写这一句Sql语句
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了谁来帮我写这一句Sql语句相关的知识,希望对你有一定的参考价值。
我建立了一张表,表中有几个字段,我怎样通过查询分析器查询到表中所有的字段名.
参考技术A SQL SERVER查看所有表名:
select name from sysobjects where type='U'
查询表的所有字段名:
Select name from syscolumns Where ID=OBJECT_ID('表名')
select * from information_schema.tables
select * from information_schema.views
select * from information_schema.columns
ACCESS
查看所有表名:
select name from MSysObjects where type=1 and flags=0
MSysObjects是系统对象,默认情况是隐藏的。通过工具、选项、视图、显示、系统对象可以使之显示出来。
参考资料:http://hi.baidu.com/yongfa365/blog/item/b35dc8ead20584d3d439c9d1.html
回答者:yongfa365 - 江湖少侠 六级 4-3 10:40 参考技术B 查询分析器不能查字段名,只能查数据
但是可以打入Select * from Table 来显示所以数据,在查询分析器中是能看到最上面的字段名的。 参考技术C <%
dsn = "DSN=DSNName"
Const adSchemaTables = 20
adSchemaColumns = 4
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open dsn
Set rstSchema = oConn.OpenSchema(adSchemaColumns)
response.write "<table>"
response.write "<tr><td>Table name</td><td>field name</td><td>field type</td><td>is nullable</td><td>field size</td></tr>"
tablename=""
Do Until rstSchema.EOF
response.write "<tr><td>"
if rstSchema("Table_name") <> tablename then
response.write rstSchema("Table_name")
tablename = rstSchema("Table_name")
else
response.write " "
end if
response.write "</td><td>"& rstschema("column_Name") & "</td><td>"
select case rstschema("data_type")
case "130"
if rstschema("CHARACTER_MAXIMUM_LENGTH") = 1073741823 then
response.write "Memo"
else
response.write "Text"
end if
case 135
response.write "Date/Time"
case 3
response.write "Long Integer"
case 11
response.write "Yes/No"
case 131
response.write "Currency"
case else
response.write rstschema("data_type")
end select
response.write "</td><td>" & rstschema("is_nullable") & "</td><td>"
if rstschema("CHARACTER_MAXIMUM_LENGTH") <> 1073741823 then
response.write rstschema("CHARACTER_MAXIMUM_LENGTH")
else
response.write " "
end if
response.write "</td></tr>"
rstSchema.MoveNext
Loop
response.write "</table>"
%>本回答被提问者采纳 参考技术D 系统表:
select name
from syscolumns
where id =object_id('表名') 第5个回答 2007-05-11 select top 0 * from [tableName]
在SQL SERVER中,怎样查询每门功课成绩最好的前两名,帮我写一下,谢谢,请补充:
create table SC(
S# varchar(10), /*学号
C# varchar(10), /*课号
score decimal(18,1) /*成绩
)
insert into sc values('01' , '01' , 80)
insert into sc values('01' , '02' , 90)
insert into sc values('01' , '03' , 99)
insert into sc values('02' , '01' , 70)
insert into sc values('02' , '02' , 60)
insert into sc values('02' , '03' , 80)
insert into sc values('03' , '01' , 80)
insert into sc values('03' , '02' , 80)
insert into sc values('03' , '03' , 80)
insert into sc values('04' , '01' , 50)
insert into sc values('04' , '02' , 30)
insert into sc values('04' , '03' , 20)
insert into sc values('05' , '01' , 76)
insert into sc values('05' , '02' , 87)
insert into sc values('06' , '01' , 31)
insert into sc values('06' , '03' , 34)
insert into sc values('07' , '02' , 89)
insert into sc values('07' , '03' , 98)
go
查询每门功课成绩最好的前两名,求高手指教。
最后的执行结果是:
01 01 80.0
03 01 80.0
01 02 90.0
07 02 89.0
01 03 99.0
07 03 98.0
select sc1.s#,sc1.c#,sc1.score from sc sc1 where score in
(select top 2 sc2.score from sc sc2
where sc2.C# = sc1.C# order by sc2.score desc)
order by sc1.C# , sc1.score desc
这样的语句也能实现同样的功能,但我有点看不太懂,能各位高手能帮我分析一下吗,呵呵。谢谢。where sc2.C# = sc1.C#这里又用到了SC1,感觉有点头晕。
S# varchar(10), --学号
C# varchar(10), --课号
score decimal(18,1) --成绩
)
insert into #sc values('01' , '01' , 80)
insert into #sc values('01' , '02' , 90)
insert into #sc values('01' , '03' , 99)
insert into #sc values('02' , '01' , 70)
insert into #sc values('02' , '02' , 60)
insert into #sc values('02' , '03' , 80)
insert into #sc values('03' , '01' , 80)
insert into #sc values('03' , '02' , 80)
insert into #sc values('03' , '03' , 80)
insert into #sc values('04' , '01' , 50)
insert into #sc values('04' , '02' , 30)
insert into #sc values('04' , '03' , 20)
insert into #sc values('05' , '01' , 76)
insert into #sc values('05' , '02' , 87)
insert into #sc values('06' , '01' , 31)
insert into #sc values('06' , '03' , 34)
insert into #sc values('07' , '02' , 89)
insert into #sc values('07' , '03' , 98)
create table #temp
(
S# varchar(10), --学号
C# varchar(10), --课号
score decimal(18,1) --成绩
)
insert into #temp
select top 2 *from #SC where C#='01' order by score desc
insert into #temp
select top 2 *from #SC where C#='02' order by score desc
insert into #temp
select top 2 *from #SC where C#='03' order by score desc
select *from #temp
drop table #temp
drop table #SC
运行结果
S# C# score
01 01 80.0
03 01 80.0
01 02 90.0
07 02 89.0
01 03 99.0
07 03 98.0 参考技术A select * from
(
select top 2 * from SC where C#='01' order by score desc
) a
union
select * from
(
select top 2 * from SC where C#='02' order by score desc
) b
union
select * from
(
select top 2 * from SC where C#='03' order by score desc
) c
order by C#,S#,score本回答被提问者采纳 参考技术B SELECT
*
FROM
SC
WHERE
( SELECT
COUNT(1)
FROM
SC SC1
WHERE
SC.C# = SC1.C#
AND SC.score < SC1.score
) < 2
ORDER BY
C#,S#追问
1, SC.score < SC1.score
这条语句是什么意思啦?
2,()<2为什么,括号内为什么要小于2呢?
select * from sc a
where s# in (
select s# from (select top 2 b.score,s# from sc b
where b.c#=a.c#
group by score,s#
order by score desc) c
)
order by c#,score desc 参考技术D 单独科目去查吧,一起查我也不会,单独查某门科目前两名用top就可以追问
这样查我也会,还是多学学吧。
以上是关于谁来帮我写这一句Sql语句的主要内容,如果未能解决你的问题,请参考以下文章
谁来帮我解释一下 flash 中的var 变量的用法?谁能让我理解它我追加50分