(Sql Subqueries with 3 tables joined) With Count and Avg comparisson [on hold]2019 Community Moderator ElectionAdd a column with a default value to an existing table in SQL ServerSQL update query using joinsCount(*) vs Count(1) - SQL ServerHow can I do an UPDATE statement with JOIN in SQL?SQL Server: How to Join to first rowFinding duplicate values in a SQL tableFind all tables containing column with specified name - MS SQL ServerHow to Delete using INNER JOIN with SQL Server?Count and Avg in query to determine if result is greater than xhow to select from multiple genres in the same column

Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?

ER diagram relationship node size adjustment

From an axiomatic set theoric approach why can we take uncountable unions?

Why restrict private health insurance?

Why is a very small peak with larger m/z not considered to be the molecular ion?

QQ Plot and Shapiro Wilk Test Disagree

What is the generally accepted pronunciation of “topoi”?

How to design an organic heat-shield?

What is the population of Romulus in the TNG era?

How do spaceships determine each other's mass in space?

Is this Paypal Github SDK reference really a dangerous site?

What sort of fish is this

When Schnorr signatures are part of Bitcoin will it be possible validate each block with only one signature validation?

Making a kiddush for a girl that has hard time finding shidduch

What is Tony Stark injecting into himself in Iron Man 3?

Possible to detect presence of nuclear bomb?

Can the alpha, lambda values of a glmnet object output determine whether ridge or Lasso?

NASA's RS-25 Engines

Is it safe to abruptly remove Arduino power?

Does "Until when" sound natural for native speakers?

Why does cron require MTA for logging?

Why does Solve lock up when trying to solve the quadratic equation with large integers?

Recommendation letter by significant other if you worked with them professionally?

Doubts in understanding some concepts of potential energy



(Sql Subqueries with 3 tables joined) With Count and Avg comparisson [on hold]



2019 Community Moderator ElectionAdd a column with a default value to an existing table in SQL ServerSQL update query using joinsCount(*) vs Count(1) - SQL ServerHow can I do an UPDATE statement with JOIN in SQL?SQL Server: How to Join to first rowFinding duplicate values in a SQL tableFind all tables containing column with specified name - MS SQL ServerHow to Delete using INNER JOIN with SQL Server?Count and Avg in query to determine if result is greater than xhow to select from multiple genres in the same column










0















How can I count the rental quantity and compare the result to the average rental quantity. after that I need to display the Title of the movie that has greater rental qtty than the average.



TblMovie
MovID
Title
MediaType
Price
QttyofDisc
DateAdded
Genre



TblBorrowDetails
BorrowNo
MovID



TblBorrow
BorrowNo
BorrowDate
MemberID



To Count how many Times The Movie was borrowed I Counted(BorrowNo)










share|improve this question







New contributor




chris chan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as too broad by Vogel612, greg-449, EdChum, Matteo Baldi, FluffyKitten Mar 7 at 9:06


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • you need to provide the sample data and expected output also tag the appropriate database like 'mysql', 'sql server' or any other db which you are using

    – PSK
    Mar 7 at 4:50
















0















How can I count the rental quantity and compare the result to the average rental quantity. after that I need to display the Title of the movie that has greater rental qtty than the average.



TblMovie
MovID
Title
MediaType
Price
QttyofDisc
DateAdded
Genre



TblBorrowDetails
BorrowNo
MovID



TblBorrow
BorrowNo
BorrowDate
MemberID



To Count how many Times The Movie was borrowed I Counted(BorrowNo)










share|improve this question







New contributor




chris chan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as too broad by Vogel612, greg-449, EdChum, Matteo Baldi, FluffyKitten Mar 7 at 9:06


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • you need to provide the sample data and expected output also tag the appropriate database like 'mysql', 'sql server' or any other db which you are using

    – PSK
    Mar 7 at 4:50














0












0








0








How can I count the rental quantity and compare the result to the average rental quantity. after that I need to display the Title of the movie that has greater rental qtty than the average.



TblMovie
MovID
Title
MediaType
Price
QttyofDisc
DateAdded
Genre



TblBorrowDetails
BorrowNo
MovID



TblBorrow
BorrowNo
BorrowDate
MemberID



To Count how many Times The Movie was borrowed I Counted(BorrowNo)










share|improve this question







New contributor




chris chan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












How can I count the rental quantity and compare the result to the average rental quantity. after that I need to display the Title of the movie that has greater rental qtty than the average.



TblMovie
MovID
Title
MediaType
Price
QttyofDisc
DateAdded
Genre



TblBorrowDetails
BorrowNo
MovID



TblBorrow
BorrowNo
BorrowDate
MemberID



To Count how many Times The Movie was borrowed I Counted(BorrowNo)







sql database visual-studio






share|improve this question







New contributor




chris chan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




chris chan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




chris chan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Mar 7 at 4:49









chris chanchris chan

1




1




New contributor




chris chan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





chris chan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






chris chan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as too broad by Vogel612, greg-449, EdChum, Matteo Baldi, FluffyKitten Mar 7 at 9:06


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









put on hold as too broad by Vogel612, greg-449, EdChum, Matteo Baldi, FluffyKitten Mar 7 at 9:06


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • you need to provide the sample data and expected output also tag the appropriate database like 'mysql', 'sql server' or any other db which you are using

    – PSK
    Mar 7 at 4:50


















  • you need to provide the sample data and expected output also tag the appropriate database like 'mysql', 'sql server' or any other db which you are using

    – PSK
    Mar 7 at 4:50

















you need to provide the sample data and expected output also tag the appropriate database like 'mysql', 'sql server' or any other db which you are using

– PSK
Mar 7 at 4:50






you need to provide the sample data and expected output also tag the appropriate database like 'mysql', 'sql server' or any other db which you are using

– PSK
Mar 7 at 4:50













2 Answers
2






active

oldest

votes


















0














You have not mentioned any database so not sure if row_number() with partition can be used or not, but you can achieve this using standard sql query like following.



select m.MovID, 
m.Title
from (select m.MovID,
m.Title,
ctBorrow,
Avg(ctBorrow) avgBorrow
from (select m.MovID,
m.Title,
Count(br.BorrowNo) ctBorrow
from TblMovie m
inner join TblBorrowDetails tb
on tb.MovID = m.MovID
inner join TblBorrow br
on br.BorrowNo = tb.BorrowNo
group by m.MovID,
m.Title)t
group by m.MovID,
m.Title,
ctBorrow) t1
where ctBorrow > avgBorrow





share|improve this answer






























    0














    I assume you need a list of movies which were borrowed more than the average of all borrowed movies.



    The query below should get you that.
    Please find the fiddle here I have removed some unwanted columns from the tables.



    SELECT M.*
    FROM TblMovie M
    JOIN TblBorrowDetails BD1 ON M.MovID = BD1.MovID
    GROUP BY M.MovID, M.Title
    HAVING COUNT(BD1.MovID) >
    (
    SELECT t1.MAvg
    FROM
    (
    SELECT AVG(MCount) AS MAvg
    FROM
    (
    SELECT COUNT(BD2.MovID) AS MCount
    FROM TblBorrowDetails BD2
    GROUP BY BD2.MovID
    )t
    )t1
    )





    share|improve this answer





























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      You have not mentioned any database so not sure if row_number() with partition can be used or not, but you can achieve this using standard sql query like following.



      select m.MovID, 
      m.Title
      from (select m.MovID,
      m.Title,
      ctBorrow,
      Avg(ctBorrow) avgBorrow
      from (select m.MovID,
      m.Title,
      Count(br.BorrowNo) ctBorrow
      from TblMovie m
      inner join TblBorrowDetails tb
      on tb.MovID = m.MovID
      inner join TblBorrow br
      on br.BorrowNo = tb.BorrowNo
      group by m.MovID,
      m.Title)t
      group by m.MovID,
      m.Title,
      ctBorrow) t1
      where ctBorrow > avgBorrow





      share|improve this answer



























        0














        You have not mentioned any database so not sure if row_number() with partition can be used or not, but you can achieve this using standard sql query like following.



        select m.MovID, 
        m.Title
        from (select m.MovID,
        m.Title,
        ctBorrow,
        Avg(ctBorrow) avgBorrow
        from (select m.MovID,
        m.Title,
        Count(br.BorrowNo) ctBorrow
        from TblMovie m
        inner join TblBorrowDetails tb
        on tb.MovID = m.MovID
        inner join TblBorrow br
        on br.BorrowNo = tb.BorrowNo
        group by m.MovID,
        m.Title)t
        group by m.MovID,
        m.Title,
        ctBorrow) t1
        where ctBorrow > avgBorrow





        share|improve this answer

























          0












          0








          0







          You have not mentioned any database so not sure if row_number() with partition can be used or not, but you can achieve this using standard sql query like following.



          select m.MovID, 
          m.Title
          from (select m.MovID,
          m.Title,
          ctBorrow,
          Avg(ctBorrow) avgBorrow
          from (select m.MovID,
          m.Title,
          Count(br.BorrowNo) ctBorrow
          from TblMovie m
          inner join TblBorrowDetails tb
          on tb.MovID = m.MovID
          inner join TblBorrow br
          on br.BorrowNo = tb.BorrowNo
          group by m.MovID,
          m.Title)t
          group by m.MovID,
          m.Title,
          ctBorrow) t1
          where ctBorrow > avgBorrow





          share|improve this answer













          You have not mentioned any database so not sure if row_number() with partition can be used or not, but you can achieve this using standard sql query like following.



          select m.MovID, 
          m.Title
          from (select m.MovID,
          m.Title,
          ctBorrow,
          Avg(ctBorrow) avgBorrow
          from (select m.MovID,
          m.Title,
          Count(br.BorrowNo) ctBorrow
          from TblMovie m
          inner join TblBorrowDetails tb
          on tb.MovID = m.MovID
          inner join TblBorrow br
          on br.BorrowNo = tb.BorrowNo
          group by m.MovID,
          m.Title)t
          group by m.MovID,
          m.Title,
          ctBorrow) t1
          where ctBorrow > avgBorrow






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 5:03









          PSKPSK

          12.2k31633




          12.2k31633























              0














              I assume you need a list of movies which were borrowed more than the average of all borrowed movies.



              The query below should get you that.
              Please find the fiddle here I have removed some unwanted columns from the tables.



              SELECT M.*
              FROM TblMovie M
              JOIN TblBorrowDetails BD1 ON M.MovID = BD1.MovID
              GROUP BY M.MovID, M.Title
              HAVING COUNT(BD1.MovID) >
              (
              SELECT t1.MAvg
              FROM
              (
              SELECT AVG(MCount) AS MAvg
              FROM
              (
              SELECT COUNT(BD2.MovID) AS MCount
              FROM TblBorrowDetails BD2
              GROUP BY BD2.MovID
              )t
              )t1
              )





              share|improve this answer



























                0














                I assume you need a list of movies which were borrowed more than the average of all borrowed movies.



                The query below should get you that.
                Please find the fiddle here I have removed some unwanted columns from the tables.



                SELECT M.*
                FROM TblMovie M
                JOIN TblBorrowDetails BD1 ON M.MovID = BD1.MovID
                GROUP BY M.MovID, M.Title
                HAVING COUNT(BD1.MovID) >
                (
                SELECT t1.MAvg
                FROM
                (
                SELECT AVG(MCount) AS MAvg
                FROM
                (
                SELECT COUNT(BD2.MovID) AS MCount
                FROM TblBorrowDetails BD2
                GROUP BY BD2.MovID
                )t
                )t1
                )





                share|improve this answer

























                  0












                  0








                  0







                  I assume you need a list of movies which were borrowed more than the average of all borrowed movies.



                  The query below should get you that.
                  Please find the fiddle here I have removed some unwanted columns from the tables.



                  SELECT M.*
                  FROM TblMovie M
                  JOIN TblBorrowDetails BD1 ON M.MovID = BD1.MovID
                  GROUP BY M.MovID, M.Title
                  HAVING COUNT(BD1.MovID) >
                  (
                  SELECT t1.MAvg
                  FROM
                  (
                  SELECT AVG(MCount) AS MAvg
                  FROM
                  (
                  SELECT COUNT(BD2.MovID) AS MCount
                  FROM TblBorrowDetails BD2
                  GROUP BY BD2.MovID
                  )t
                  )t1
                  )





                  share|improve this answer













                  I assume you need a list of movies which were borrowed more than the average of all borrowed movies.



                  The query below should get you that.
                  Please find the fiddle here I have removed some unwanted columns from the tables.



                  SELECT M.*
                  FROM TblMovie M
                  JOIN TblBorrowDetails BD1 ON M.MovID = BD1.MovID
                  GROUP BY M.MovID, M.Title
                  HAVING COUNT(BD1.MovID) >
                  (
                  SELECT t1.MAvg
                  FROM
                  (
                  SELECT AVG(MCount) AS MAvg
                  FROM
                  (
                  SELECT COUNT(BD2.MovID) AS MCount
                  FROM TblBorrowDetails BD2
                  GROUP BY BD2.MovID
                  )t
                  )t1
                  )






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 7 at 5:33









                  Priyank PanchalPriyank Panchal

                  380410




                  380410













                      Popular posts from this blog

                      How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

                      Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                      List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229