where del_flag=0 和 id如果为空的话,bid=0 如果id不等于空的话,id=0
时间: 2023-08-22 11:09:29 浏览: 106
您的问题是关于SQL语句的,您可以使用以下语句实现您的需求:
```
UPDATE table_name SET bid = 0 WHERE del_flag = 0 AND id IS NULL;
UPDATE table_name SET id = 0, bid = 0 WHERE del_flag = 0 AND id IS NOT NULL;
```
以上语句中,第一条语句会将id为NULL的记录的bid字段更新为0,第二条语句会将id不为NULL的记录的bid和id字段都更新为0。这里假设表名为table_name,您需要将其替换为您实际使用的表名。
相关问题
where del_flag=0 和 id如果为空的话,用bid=0这个sql怎么写
您可以使用以下 SQL 语句来实现:
```
SELECT * FROM table_name WHERE del_flag=0 AND (id IS NULL OR id='') AND bid=0;
```
这个 SQL 语句的意思是从 `table_name` 表中选择所有 `del_flag` 为 0 并且 `id` 是空或者为 null,以及 `bid` 等于 0 的记录。
select i.id, i.name, i.group_id, i.max_people, i.create_time, u.nick_name, w.shrimp, gb.total, gpo.order_total, gpo.rake_total, gpo.shell_total, gpo.consume_total from im_group_information i left join im_group g on g.group_id = i.group_id and g.admin=2 left join (select group_id, count(group_id) total from im_group where is_delete=0 group by group_id) gb on gb.group_id = i.group_id left join (select bid, count(bid) order_total, sum(rake) rake_total, sum(price) shell_total, count(distinct uid) consume_total from g_prop_order where is_delete=0 group by bid) gpo on gpo.bid = g.u_id left join u_user u on u.id = g.u_id left join u_wallet w on w.id = g.u_id left join (select uid, count(distinct uid) offline_total from u_online_log group by uid) l on g.u_id = l.uid where i.is_delete = 0;怎么查到im_group_information群组表中七天内登陆过的用户数量
可以使用子查询结合条件判断的方式来查询七天内登陆过的用户数量,具体实现如下:
```
SELECT COUNT(DISTINCT l.uid) AS login_total
FROM im_group_information i
LEFT JOIN im_group g ON g.group_id = i.group_id AND g.admin = 2
LEFT JOIN u_user u ON u.id = g.u_id
LEFT JOIN u_online_log l ON g.u_id = l.uid
WHERE i.is_delete = 0
AND l.login_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)
```
这里使用了 `COUNT(DISTINCT l.uid)` 来统计七天内登陆过的用户数量,同时在 `WHERE` 子句中加入条件 `l.login_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)` 来筛选出七天内登陆过的用户。
阅读全文