这些SQL查询对给定的表有意义吗?

时间:2022-11-01 23:38:28

这些SQL查询对给定的表有意义吗?

Give the following two SQL tables I want to run two queries (venue_id is a foreign key with id from the venues table):

给出以下两个我希望运行两个查询的SQL表(venue_id是一个带有来自场地表的id的外键):

SELECT venues.name FROM venues INNER JOIN users ON venues.venue_id = users.venue_id WHERE users.id = {param}

SELECT venues.name FROM场所INNER JOIN用户ON venues.venue_id = users.venue_id WHERE users.id = {param}

To return the venue name associated with the user_id that was passed in

返回与传入的user_id关联的场地名称

SELECT users.name FROM users WHERE users.venue_id = {param] AND users.expiration_time > CURRENT_TIMESTAMP

SELECT users.name FROM users WHERE users.venue_id = {param] AND users.expiration_time> CURRENT_TIMESTAMP

To return all the current users with a given venue_id where the expiration_time is after the current time.

返回具有给定venue_id的所有当前用户,其中expiration_time在当前时间之后。

Do both these queries do what I expect them to do?

这两个查询都做我期望他们做的事吗?

Thanks!

1 个解决方案

#1


1  

SELECT venues.name FROM venues INNER JOIN users ON venues.id = users.venue_id WHERE users.id = {param}

SELECT venues.name FROM场所INNER JOIN用户ON venues.id = users.venue_id WHERE users.id = {param}

SELECT users.name FROM users WHERE users.venue_id = {param] AND users.expiration_time > CURRENT_TIMESTAMP

SELECT users.name FROM users WHERE users.venue_id = {param] AND users.expiration_time> CURRENT_TIMESTAMP

Both queries should be doing what you expect them to do

两个查询都应该按照您的期望进行

#1


1  

SELECT venues.name FROM venues INNER JOIN users ON venues.id = users.venue_id WHERE users.id = {param}

SELECT venues.name FROM场所INNER JOIN用户ON venues.id = users.venue_id WHERE users.id = {param}

SELECT users.name FROM users WHERE users.venue_id = {param] AND users.expiration_time > CURRENT_TIMESTAMP

SELECT users.name FROM users WHERE users.venue_id = {param] AND users.expiration_time> CURRENT_TIMESTAMP

Both queries should be doing what you expect them to do

两个查询都应该按照您的期望进行