SQL isset 并且不显示空白“单元格”

发布于 2024-09-06 12:40:10 字数 349 浏览 3 评论 0原文

我使用我的 MySQL 数据库表之一作为实际表,其中每一列都是一天中的时间,并且有一列称为日。你猜对了,在day中它表示星期几,在其余的单元格中它表示当时发生的事情。

我想做的只是显示其中有价值的单元格。就我而言,我总是将所有行和两列填满。这两列是“day”和“19:00”,但是将来我可能会添加“18:00”等的值。

那么,我如何才能只选择其中包含数据的列和行呢?某种类型的“哪里:有数据”?

谢谢!

编辑:图片Database

I'm using one of my MySQL database tables as an actual table, with times of the day as each column, and one column called day. You guessed it, in day it says the day of the week, and in the rest of the cells it says what is happening at that time.

What I want to do is only show the cells that have value in it. In my case, I'm always going to have all the rows and 2 columns full. The 2 columns are 'day' and '19:00', however in the future I might add values for '18:00' etc.

So, how can I only SELECT the columns and rows which have data in them? Some type of 'WHERE: there is data'?

Thanks!

EDIT: PictureDatabase

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝色星空 2024-09-13 12:40:11

将时间或日期作为列意味着您的字段名称中包含数据。数据属于表内部,因此您应该规范化数据库:

table Calendar
--------------
Day
TimeOfDay
Appointment

这样您就不会在表中获得大量空字段,并且不必更改数据库设计来添加一天中的另一个时间。

现在您可以轻松地仅获取存在的时间:

select Day, TimeOfDay, Appointment from Calendar

Having time or day as columns means that you have data in your field names. Data belongs inside the table, so you should normalise the database:

table Calendar
--------------
Day
TimeOfDay
Appointment

This way you don't get a lot of empty fields in the table, and you don't have to change the database design to add another time of day.

Now you can easily fetch only the times that exist:

select Day, TimeOfDay, Appointment from Calendar
余生再见 2024-09-13 12:40:11

根据我的收集,您正在寻找类似的内容,

WHERE col1 IS NOT NULL

但是如果您可以详细说明您的模式,特别是如果您可以绘制一个示例表,那将会很有帮助。

From what I gathere you are looking something along the lines of

WHERE col1 IS NOT NULL

But it would be helpful if you could elaborate more on your schema, especially if you could draw a sample table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文