有一个表a,请写出一条sql语句找出所有根user_code重复,且open_time与close_time存
时间: 2023-05-24 07:05:06 浏览: 125
在同一天的记录:
```
SELECT * FROM a
WHERE DATE(open_time) = DATE(close_time)
AND user_code IN (
SELECT user_code FROM a
GROUP BY user_code
HAVING COUNT(*) > 1
)
ORDER BY user_code;
```
相关问题
cursor B1 is select user_id, user_code, user_name, electric_power_ct, elec_number, zone_code from be_user t where t.zone_code = Chzonecode and t.user_type in ('0', '1', '8', '15'); B B1%rowtype;把这段sql中Chzonecode改成if判断不为空的时候才在where后面去匹配
你可以这样修改:
```
IF Chzonecode IS NOT NULL THEN
OPEN B1 FOR
SELECT user_id, user_code, user_name, electric_power_ct, elec_number, zone_code
FROM be_user t
WHERE t.zone_code = Chzonecode AND t.user_type IN ('0', '1', '8', '15');
ELSE
OPEN B1 FOR
SELECT user_id, user_code, user_name, electric_power_ct, elec_number, zone_code
FROM be_user t
WHERE t.user_type IN ('0', '1', '8', '15');
END IF;
FETCH B1 INTO B;
WHILE B1%FOUND LOOP
-- do something with B
FETCH B1 INTO B;
END LOOP;
CLOSE B1;
```
这样修改后,如果Chzonecode为空,就会执行第二个SELECT语句,否则就执行第一个SELECT语句。
阅读全文