使用join,distinct,count和where的复杂SQL请求 [英] Complex SQL request using join, distinct, count, and where

查看:58
本文介绍了使用join,distinct,count和where的复杂SQL请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表:circuit(id_circuit,距离)和circuit_langue(id_circuit_language,#id_circuit,语言,标题). 我想获取具有两种以上语言的电路列表.

I have 2 tables: circuit(id_circuit, distance) and circuit_langue(id_circuit_language, #id_circuit, language, title). I want to get the list of circuit which have more than 2 languages.

推荐答案

不需要join:

select cl.id_circuit
from circuit_langue cl
group by cl.id_circuit
having count(*) >= 3;

这假定表中没有重复项.如果有,那么您要使用count(distinct language) >= 3.

This assumes no duplicates in the table. If there are, then you want to use count(distinct language) >= 3.

这篇关于使用join,distinct,count和where的复杂SQL请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆