易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL语句该怎么写

SQL code:

create table table_name
(
subjectId int, --课程
name nvarchar(20), --姓名
score numeric(12,2), --分数
class int --班级
)

查询结果:
subjectId name score subjectId name score
1 xx 50 1 yy 60
2 xx 75 2 yy 96
3 xx 85 3 yy 48
4 xx 70 1 zz 70


解释一下:主要是分两列去查找记录,左边的结果是从class=1查出来的,右边的结果是从class=2查出来的,
要合在一起。
当然了,table_name这个表里只存放了两个班级的信息。如果两个班级考试的科目*人数不相等,那么少的那个
的subjectId ='',name=''score=''

SQL code:
select T1.*,T2.* from
(
select *
from tb
where class=1
)T1,
(
select *
from tb
where class=2
)T2
where T1.subjectid = T2.subjectis


沙发
回复内容太短了!


引用
SQL codeselect T1.*,T2.*from
(select*from tbwhere class=1
)T1,
(select*from tbwhere class=2
)T2where T1.subjectid= T2.subjectis

你有必要这么快吗?

楼上的两位,我没有说同一行的 subjectId 要相同



相关问答:

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

ASP链接SQL的简单登陆界面 - .NET技术 / ASP.NET

protected void btnLogin_Click(object sender, EventArgs e)
  {
  SqlConnection conn = new SqlConnection("Server = (local);user id = sa;pwd = 1;database = Login");
&nb ......

求一sql语句 - MS-SQL Server / 基础类


id bh  
1 10
2 11
3 12 
4 15
5 16
6 22
7 25
8 26
9 27
10 28
将bh按连续分段出来返回字符串:
10~12,15~16,22,25~28
SQL code:


declare @t tabl ......

MS SQL作业问题 - MS-SQL Server / 应用实例

如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP

参考:http://hi.baidu.com/toiota ......

如何使用MySQL - MS-SQL Server / 基础类

刚刚接触MySQL,不知道该如何去查看数据,插入数据,创建数据库、表,用哪为前辈能指教一二?

MySQL 5.1参考手册

引用
兄弟你会结贴吗?
mysql 参考手册

baidu

MySQL官方文档 http://dev.mysql.com/doc ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号