[英]How to delete those tuples from table given, where salary of the instructor is less than average salary of corresponding department?
[英]how to delete from one table where count less than?
我有2張桌子。
我使用此查詢來查找另一個表中一個表的字段出現次數
select t.id, t.tag_text, count(*) cnt from sms s, template as t
where s.id_template=t.id
group by t.tag_text
order by cnt desc
如果在短信中出現的行少於5次,如何從模板中刪除所有行? 這意味着如果count小於5.我使用MySQL。
您可以使用過濾器聚合結果,例如:
select t.id, t.tag_text, count(*) cnt
from sms s, template as t
where s.id_template=t.id
group by t.tag_text
having count(*) <5
order by cnt desc
並刪除例如:
delete from
from sms as s
inner join template as t on s.id_template=t.id
group by t.tag_text
having count(*) <5
delete from template
where id in
(
select id_template
from sms
group by id_template
having count(*) < 5
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.