sqlserver数据库"子连接"count数量查询
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sqlserver数据库"子连接"count数量查询相关的知识,希望对你有一定的参考价值。
car_report 是 车牌主表, plate_number 字典是car_reportd 的主键
也是 exceed_report表 和 associat_report表的外键
下面两个表 是单独查询各自的每台车的数量
select plate_number,COUNT(*) as 超速 from exceed_report group by plate_number
insert into exceed_report(plate_number)
values('粤c10090')
insert into exceed_report(plate_number)
values('粤c10060')
insert into exceed_report(plate_number)
values('粤c11662')
insert into exceed_report(plate_number)
values('粤C12353')
exceed_report 是超速表
select plate_number,COUNT(*) as 超载 from associat_report group by plate_number
associat_report 是超载表
insert into associat_report(plate_number)
values('粤c10090')
insert into associat_report(plate_number)
values('粤c10060')
------------------------------------------------------------------------------------------------
请问哪位老师sql语句能达到这样的效果啊?学生我 sql语句一般 求教.....
车牌 超速 超载
1 粤c10060 1 1
2 粤c10090 1 1
3 粤c11662 1 0
4 粤C12353 1 0
如何能达到这样的效果呢? 求老师赐教 感谢
from car_report a left join
(select plate_number,COUNT(*) as 超速 from exceed_report group by plate_number) b
on a.plate_number=b.plate_number left join
(select plate_number,COUNT(*) as 超载 from associat_report group by plate_number) c
on a.plate_number=c.plate_number 参考技术A select a.*,b.超载 from
(select plate_number,COUNT(*) as 超速 from exceed_report group by plate_number) a left join
(select plate_number,isnull(COUNT(*),0) as 超载 from associat_report group by plate_number) b on a.plate_number=b.plate_number
关于jsp连接SQLserver 2000 的问题
我的代码~~~
<%@ page contentType=\"text/html;charset=gb2312\"%>
<%@ page import=\"java.sql.*\"%>
<html>
<body>
<%
Class.forName(\"com.microsoft.jdbc.sqlserver.SQLServerDriver\").newInstance();
String url=\"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student\";
String user=\"stu\";
String password=\"stu\";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
String sql=\"select * from T_User\";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) %>
<%=rs.getString(1)%>
<%%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
然后报错是下边的
我在我的lib下装了很多包~~我不知道是什么问题~~请好心的你帮帮我~~~
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /test.jsp(1,25) quote symbol expected
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:204)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:154)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:166)
org.apache.jasper.compiler.ParserController.getPageEncodingForJspSyntax(ParserController.java:490)
org.apache.jasper.compiler.ParserController.determineSyntaxAndEncoding(ParserController.java:431)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:207)
org.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:120)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:165)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.20
我不知道怎么加200分 但是我会追加分数的
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class BaseDao
private static final String DRIVER_CLASS="com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static final String URL="jdbc:sqlserver://localhost:1433;DATABASENAME=managerNews";
private static final String UNAME="sa";
private static final String UPASSWORD="sa";
/*
* 连接数据库
*/
public Connection getConnection()
Connection conn=null;
try
Class.forName(DRIVER_CLASS);
conn=DriverManager.getConnection(URL,UNAME,UPASSWORD);
catch (Exception e)
// TODO Auto-generated catch block
e.printStackTrace();
return conn;
/*
* 关闭conn,ps,rs,释放资源
*/
public void closeAll( Connection conn, PreparedStatement ps, ResultSet rs )
/* 如果rs不空,关闭rs */
if(rs != null)
try rs.close(); catch (SQLException e) e.printStackTrace();
/* 如果pstmt不空,关闭pstmt */
if(ps!= null)
try ps.close(); catch (SQLException e) e.printStackTrace();
/* 如果conn不空,关闭conn */
if(conn != null)
try conn.close(); catch (SQLException e) e.printStackTrace();
// public static void main (String[] args)
//
// BaseDao bo= new BaseDao();
// Connection conn=null;
// conn=bo.getConnection();
// System.out.print(conn);
//
//
参考技术A <%
try
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student";
String user="stu";
String password="stu";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
String sql="select * from T_User";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
out.println(rs.getString(1)); //此处循环输出你想要的显示的
catch(Exception e)e.printStackTrace();
finally
rs.close();
stmt.close();
conn.close();
%> 参考技术B 把双引号前面的\去掉,全部的 参考技术C 将class那句改成这样: class.forname("com.microsoft.jdbc.sqlserver.sqlserverdriver");
以上是关于sqlserver数据库"子连接"count数量查询的主要内容,如果未能解决你的问题,请参考以下文章