Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQLite:查找具有特定值的集合_Sql_Sqlite - Fatal编程技术网

SQLite:查找具有特定值的集合

SQLite:查找具有特定值的集合,sql,sqlite,Sql,Sqlite,我需要找到马克和玛丽攀登过的山峰 我这样做了,但不起作用: PEAK (NAME, ELEV, DIFF, MAP, REGION) CLIMBER (NAME, SEX) PARTICIPATED (TRIP_ID, NAME) CLIMBED (TRIP_ID, PEAK, WHEN_CLIMBED) 我还试着做: select * from participated, climbed where participated.name="MAR

我需要找到马克和玛丽攀登过的山峰

我这样做了,但不起作用:

PEAK (NAME, ELEV, DIFF, MAP, REGION)
CLIMBER (NAME, SEX)
PARTICIPATED (TRIP_ID, NAME)
CLIMBED (TRIP_ID, PEAK, WHEN_CLIMBED)
我还试着做:

        select *
        from participated, climbed
        where participated.name="MARY" or "MARK" and participated.trip_id= climbed.trip_id
我将如何执行此操作?

您可以在中使用

Group By name, peak
Having name="MARY" or "MARK"
或者一个合适的或者

    select *
    from participated
    INNER JOIN  climbed ON participated.trip_id= climbed.trip_id
    where participated.name IN ("MARY" , "MARK") 

如果您只想找到两个剪辑的峰值,那么就这样做

    select *
    from participated
    INNER JOIN  climbed ON participated.trip_id= climbed.trip_id
    where participated.name = "MARY" OR  participated.name =  "MARK"

如果您只想要峰值,可以执行以下操作:

select peak
from participated
join climbed on participated.trip_id = climbed.trip_id
group by peak
having sum(name='MARY') > 0
   and sum(name='MARK') > 0

注意正确的
JOIN
语法的使用。

一式三份:和“不工作”(这是否意味着烟雾从桌面散发?它使服务器崩溃?答案错误1000倍?屏幕上有一条错误消息?)请定义“不工作”你可能想在以后的问题中避免使用这种表达方式。但根据问题的答案,这种方法“不起作用”
select c.peak
from climbed c join
     trip t
     on c.trip_id = t.trip_id
where name in ('MARY', 'MARK')
group by c.peak
having count(distinct name) = 2;