currently look same sex some question!!!

本文通过一系列SQL语句创建并填充了一个关于工资的数据表,并利用SQL的聚合函数进行了简单的统计分析,包括计数和求和操作。此外,还定义了一个存储过程用于计算男性员工的平均工资及数量。

create table wage(wage money,name1 char(4),sex char(2))
insert wage values(100.1,'zxy1','男')
select *
from wage
insert wage values(100.2,'zxz','男')
go
insert wage values(100.2,'zxl','女')
go
insert wage values(100.2,'zxw','女')
go
insert wage values(100.2,'zxx','男')
go
select count(name1)as samesexcount  ---统计出同性之人数
from wage
group by sex
go


select sum(wage)as samesexcount  ----统计出同性工资之和
from wage
group by sex  

create procedure proc_print
@wage money out,
@count int out,@num int out,@money money out
as
set @wage=(select aw.avg_wage
from (select avg(wage) as avg_wage,sex from wage,Employees
where wage.EmployeeID=Employees.EmployeeID and sex='男'
group by sex) as aw)

set @count=(select an.sex_wage
from (select count(sex) as sex_wage,sex from wage,Employees
where wage.EmployeeID=Employees.EmployeeID and sex='男'
group by sex) as an)

select * from Employees

declare @wage money
declare @money money
declare @count int
declare @num int

execute proc_print  @wage out,count out,@num out,@money out
print(convert(nvarchar(40),@wage))
print(convert(nvarchar(40),@num))

alter procedure proc_print
@wage money out,
@count int out
as
set @wage=(select aw.avg_wage
from (select avg(wage) as avg_wage,sex from wage,Employees
where wage.EmployeeID=Employees.EmployeeID and sex='男'
group by sex) as aw)

set @count=(select an.sex_wage
from (select count(sex) as sex_wage,sex from wage,Employees
where wage.EmployeeID=Employees.EmployeeID and sex='男'
group by sex) as an)

select * from Employees
go


declare @wage money
declare @count int

execute proc_print  @wage out,@count out
print(convert(nvarchar(40),@wage))
print(convert(nvarchar(40),@count))

当执行查询 BLOB 类型的 `wavedata` 数据时出现 “this operation is NOT supported currently!” 错误,可能有以下几种原因及相应的解决办法: #### 数据库驱动不兼容 不同的数据库有各自的 JDBC 驱动,且每个驱动都有特定的版本支持某些操作。如果使用的驱动版本过旧或不兼容,可能会导致某些操作不被支持。 - **解决办法**:更新数据库驱动到最新的稳定版本。以 MySQL 为例,可在 Maven 项目中更新依赖: ```xml <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.26</version> </dependency> ``` #### 数据库权限问题 如果数据库用户没有足够的权限来查询 BLOB 数据,也可能会出现此错误。 - **解决办法**:检查数据库用户的权限,确保其具有查询 BLOB 字段的权限。以 MySQL 为例,可使用以下 SQL 语句为用户授予权限: ```sql GRANT SELECT ON your_database.your_table TO 'your_user'@'your_host'; ``` #### 数据库配置问题 某些数据库可能对 BLOB 数据的处理有特定的配置要求,如果配置不正确,可能会导致操作不被支持。 - **解决办法**:检查数据库的配置文件,确保对 BLOB 数据的处理没有限制。例如,在 MySQL 中,可检查 `max_allowed_packet` 参数,若该参数设置过小,可能无法处理大的 BLOB 数据,可在 `my.cnf` 文件中增加该参数的值: ```plaintext [mysqld] max_allowed_packet = 100M ``` #### 代码逻辑问题 代码中可能存在不恰当的操作,导致数据库驱动无法正确处理 BLOB 数据。 - **解决办法**:检查代码逻辑,确保使用正确的方法来处理 BLOB 数据。例如,使用 `rs.getBlob` 或 `rs.getBinaryStream` 方法来获取 BLOB 数据,而不是使用不支持的方法: ```java import java.sql.Blob; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class BlobQueryExample { public static void main(String[] args) { String url = "jdbc:mysql://localhost:3306/your_database"; String user = "your_username"; String password = "your_password"; String sql = "SELECT wavedata FROM your_table LIMIT 1"; try (Connection conn = DriverManager.getConnection(url, user, password); PreparedStatement stmt = conn.prepareStatement(sql); ResultSet rs = stmt.executeQuery()) { if (rs.next()) { Blob blob = rs.getBlob("wavedata"); if (blob != null) { byte[] data = blob.getBytes(1, (int) blob.length()); // 处理获取到的二进制数据 System.out.println("Data length: " + data.length); blob.free(); } } } catch (SQLException e) { e.printStackTrace(); } } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值