sql - Using Cast to Convert DateTime to Date and select today's date
问题描述
I'm trying to count the number of accounts opened on today's date in the SELECT Statement. I'm doing so with an IIF statement and using CAST to convert the DateTimeStamp to Date. That said, I'm having trouble figuring out where to date column (Open_Date) and how to check to see if it's is today's date. Would I place -1 right after the ) following as date or???
COUNT(IIF(CAST(GETDATE() AS date))), SHARE.MEMBER_NBR, null)) AS ALLNEWACCOUNTSTODAY
解决方案
You can use case
expression with Open_Date
:
COUNT(CASE WHEN CONVERT(DATE, GETDATE()) = Open_Date THEN SHARE.MEMBER_NBR END) AS ALLNEWACCOUNTSTODAY
推荐阅读
- odoo - xml 记录 Ir.rule AssertionError: Element odoo has extra content: 记录
- python - confluent_kafka消费者偏移计数重置问题
- android - 以下元数据的值是多少,它是如何设置的?
- gzip - 如果 Html 文件小于 16KB,是否真的有必要对我的 Html 文件实施 Gzip?
- python - 如何在 Python Pandas 中将 unix 时间戳转换为日期时间
- javascript - Django包含使用Javascript的模板
- go - 为什么 RabbitMQ 在不使用时连接不会保持打开状态?
- thingsboard - Thingsboard PE:Cassandra 到 PostgreSQL
- image - 无法从项目文件夹中渲染图像
- windows - 使用 Powershell 禁用计算机