Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于通知新注册用户的SQL设计_Sql_Database Design_Mysqli - Fatal编程技术网

用于通知新注册用户的SQL设计

用于通知新注册用户的SQL设计,sql,database-design,mysqli,Sql,Database Design,Mysqli,我很难在新用户注册时为通知模块制定SQL 我有一个通知数据库,我设置了要发送的通知。示例: 当男人和蓝眼睛注册时发送通知; 女性注册时发送通知; 当一个蓝眼睛的棕色女人在公司工作时,发送一个通知; 根据这些规则,我们可以看到有几种可能性,因此表列是可选的 一些细节: 表列被定义为整数,因为它们是FK。我只是没有放表,因为结构是不必要的,因为SQL只会在用户和通知之间建立关系; 日期字段用于存储该人员通知的注册日期。所以我只能过滤通知新注册的用户; 表结构 初衷 我最初的想法是对每种可能性进行选择

我很难在新用户注册时为通知模块制定SQL

我有一个通知数据库,我设置了要发送的通知。示例:

当男人和蓝眼睛注册时发送通知; 女性注册时发送通知; 当一个蓝眼睛的棕色女人在公司工作时,发送一个通知; 根据这些规则,我们可以看到有几种可能性,因此表列是可选的

一些细节:

表列被定义为整数,因为它们是FK。我只是没有放表,因为结构是不必要的,因为SQL只会在用户和通知之间建立关系; 日期字段用于存储该人员通知的注册日期。所以我只能过滤通知新注册的用户; 表结构 初衷 我最初的想法是对每种可能性进行选择,并通过联盟加入:

-- Selects new users by gender notification SELECT * FROM Notification inner join User on ( User.Date >= Notification.Date and Notification.Gender = User.Gender and Notification.HairColor is null and Notification.EyeColor is null and Notification.Company is null ) union all -- Selects new users by gender and hair color notification SELECT * FROM Notification inner join User on ( User.Date >= Notification.Date and Notification.Gender = User.Gender and Notification.HairColor = User.HairColor and Notification.EyeColor is null and Notification.Company is null ) -- ... and so on, doing a select for each option, resulting in 16 selects (4 columns: gender, hair color, eye color and company) 我的问题是: 有没有其他方法可以更轻松地查询所有通知的可能性? 按照4列的结构,我们已经有16个选择。在我的真实结构中,将有更多的列,其中包含一些不可能保持这种状态的内容。 对于实现此功能的更好方法,是否还有其他建议

SELECT * 
FROM Notification
inner join User on (
    User.Date >= Notification.Date and
    (Notification.Gender is null or Notification.Gender = User.Gender) and
    (Notification.HairColor is null or Notification.HairColor = User.HairColor) and
    (Notification.EyeColor is null Notification.EyeColor = User.EyeColor) and
    (Notification.Company is null or Notification.Company = User.Company)
)

通过这种方式,您可以使用存储在表中的通知获取每个用户集。

这是我实现此用户注册/通知功能的方式:

三个表:用户、Notif\u类型、Notif\u队列。 对表用户执行insert操作时的触发器,它调用存储过程SendNotificationuser_id。 存储的proc将具有您可以超时更改的逻辑,而无需修改模式/数据。逻辑将是: 根据您的规则,选择新用户应接收的通知表单的类型; 在Notif_队列中插入一行,该行包含FK to user_id和Notif_type_id,以便通知用户的功能与通知规则完全解耦。
为什么不能只使用一个表用户,并添加一个名为[Notified]的额外字段/标志,以便每次发送通知时都将其引用到该标志


我发现使用通知表与此无关。

您是否考虑过@NeilMcGuigan该页面讨论了范例,不幸的是,这对解决我的问题没有多大帮助。我想您误解了我正在使用的功能。通知由系统配置,并可根据所做的条目进行自定义​​在通知表中。通过测试这样做的案例,似乎是有效的。看到他的回答,我觉得自己是个白痴!一个简单的解决方案,有时我们在开发应用程序时太狭隘,以至于看不到简单的问题。
SELECT * 
FROM Notification
inner join User on (
    User.Date >= Notification.Date and
    (Notification.Gender is null or Notification.Gender = User.Gender) and
    (Notification.HairColor is null or Notification.HairColor = User.HairColor) and
    (Notification.EyeColor is null Notification.EyeColor = User.EyeColor) and
    (Notification.Company is null or Notification.Company = User.Company)
)