sql >> データベース >  >> RDS >> Oracle

SQLクエリ、平均上昇、および最も多くのピークを上昇したペア

    質問1:旅行の総数(ピークが登るたびを含む)

    SELECT t1.sex, AVG(t1.peak_count) AS average
    FROM
        (SELECT sex, COUNT(trip_id) AS peak_count
         FROM climber c LEFT JOIN  participated p ON c.name = p.name GROUP BY c.name, c.sex) t1
    

    ユニークなピークが登るたびに:

    SELECT t1.sex, AVG(t1.peak_count) AS average
    FROM
        (SELECT sex, COUNT(trip_id) AS peak_count
         FROM climber c LEFT JOIN  participated p ON c.name = p.name GROUP BY c.name, c.sex) t1
    

    質問2:

    SELECT P1.Name, P2.Name, COUNT(DISTINCT p1.trip_id) AS trips
    FROM participated p1 INNER JOIN  participated p2 ON p1.trip_id = p2.trip_id
    WHERE p1.name > p2.name -- > instead of <> gets only one of the pairs
    GROUP BY P1.Name, P2.Name 
    HAVING COUNT(DISTINCT p1.trip_id) > 0
    ORDER BY trips DESC
    

    質問3:

    SELECT p.name, cl.when AS span_begin_date, DATEADD(day, 60, cl.when) AS span_end_date, count(c2.trip_id) AS peaks
    FROM climbed cl LEFT JOIN 
    climbed c2 ON c2.when BETWEEN cl.when AND DATEADD(day, 60, cl.when)
    GROUP BY p.name, cl.when, DATEADD(day, 60, cl.when)
    HAVING COUNT(c2.trip_id) > 20
    ORDER BY peaks
    


    1. 一連の日付の最も近い記録

    2. MariaDBでのUTC_TIME()のしくみ

    3. Dockerを使用してWebアプリを起動すると、Postgresql DBに接続できませんか?

    4. mysql結果データセット内の次のレコードを取得するにはどうすればよいですか?