(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

                      Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

                      Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

                      How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page