How could I form a tsql query with 'and' and 'not' for a result

Mahmoud

I have the following question:

For each city display the number of clients who only rented cars of type 'Toyota' or 'BMW' and never rented 'Mercedes'

The tables are as follows:

Car [CarId int, type varchar(30)]

Client [ClientId int, CityId int, Name varchar(30)]

City [CityId int, CityName varchar(30)]

Rent [CarId int, ClientId int, days_number int]

I don't know how would I formulate this query I tried hard but nothing worked until now.

Mahmoud

Declare @count1 int, @count2 int

Select @count1 = Count(*)

From Client inner join Rent

on Client.ClientId = Rent.ClientId

inner join Car

on Car.CarId = Rent.CarId

Where Car.type In( 'Toyota','BMW')

--except

Select @count2 = Count(*)

From Client inner join Rent

on Client.ClientId = Rent.ClientId

inner join Car

on Car.CarId = Rent.CarId

Where Car.type = 'Merccedes'

Select (@count1 - @count2)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How could I form a tsql query with 'and' and 'not' for a result

From Dev

TSQL - How to format result of a query?

From Dev

TSQL: how to delete last record from query result if record is NULL

From Dev

How could I get the result for "For" operation?

From Dev

How could I store form values in an Array?

From Dev

I have two query And i want to get result form both

From Dev

How could I refactor this bit of code here to achieve the same result?

From Dev

How could I reload ajax json result to datatable?

From Dev

How i can use result of subquery in this query?

From Dev

How do I query SQlite using python and then compare the query result?

From Dev

How can I use a query result as a column for a separate query?

From Dev

How can I use a query result as a column for a separate query?

From Dev

How do I form this complex query in Hibernate?

From Dev

How to convert TSQL query into MYSQL query?

From Dev

How could I use join query to find the intersection

From Dev

How could I make a mDNS Query with Pcap.net?

From Dev

How could I check a single document against an existing mongoose query?

From Dev

how could i handle this linq query and compare it with and int in an if-statement?

From Dev

How could i query operation log(Oplog) in MongoDB?

From Dev

How could I query embed object field name in mongodb / pymongo?

From Dev

How could i query operation log(Oplog) in MongoDB?

From Dev

how could i handle this linq query and compare it with and int in an if-statement?

From Dev

How could I sort the array of entity objects returned by this doctrine query?

From Dev

How do I convert this tSQL statement to LINQ using group by in a sub query

From Dev

Java How can I correctly transform a result from a jdbc query

From Dev

How can I insert the query result into a table in mysql?

From Dev

How should I order a subset of a query returned and place it on the top of the result?

From Dev

How do I store a mongodb query result in a variable?

From Dev

How do I put a previous result into the next query? MYSQL

Related Related

  1. 1

    How could I form a tsql query with 'and' and 'not' for a result

  2. 2

    TSQL - How to format result of a query?

  3. 3

    TSQL: how to delete last record from query result if record is NULL

  4. 4

    How could I get the result for "For" operation?

  5. 5

    How could I store form values in an Array?

  6. 6

    I have two query And i want to get result form both

  7. 7

    How could I refactor this bit of code here to achieve the same result?

  8. 8

    How could I reload ajax json result to datatable?

  9. 9

    How i can use result of subquery in this query?

  10. 10

    How do I query SQlite using python and then compare the query result?

  11. 11

    How can I use a query result as a column for a separate query?

  12. 12

    How can I use a query result as a column for a separate query?

  13. 13

    How do I form this complex query in Hibernate?

  14. 14

    How to convert TSQL query into MYSQL query?

  15. 15

    How could I use join query to find the intersection

  16. 16

    How could I make a mDNS Query with Pcap.net?

  17. 17

    How could I check a single document against an existing mongoose query?

  18. 18

    how could i handle this linq query and compare it with and int in an if-statement?

  19. 19

    How could i query operation log(Oplog) in MongoDB?

  20. 20

    How could I query embed object field name in mongodb / pymongo?

  21. 21

    How could i query operation log(Oplog) in MongoDB?

  22. 22

    how could i handle this linq query and compare it with and int in an if-statement?

  23. 23

    How could I sort the array of entity objects returned by this doctrine query?

  24. 24

    How do I convert this tSQL statement to LINQ using group by in a sub query

  25. 25

    Java How can I correctly transform a result from a jdbc query

  26. 26

    How can I insert the query result into a table in mysql?

  27. 27

    How should I order a subset of a query returned and place it on the top of the result?

  28. 28

    How do I store a mongodb query result in a variable?

  29. 29

    How do I put a previous result into the next query? MYSQL

HotTag

Archive