Skip to content

Tag: mysql

How can I condition the time column?

There is a column representing 24 hours. Data comes in every 15 minutes. For example, at 10:15, the value is entered in the DateTime column of the 10H column. But… The client wants to set the …

How to name a column that is also a function name in SQL?

For example, this doesn’t work, That is because Rank is also a function. I tried to replace Rank with [Rank] but that still doesn’t work. So, what is the solution? Answer You can give it a different name. That is what I would recommend. But absent that, the escape character in MySQL is the backtic…

How can I replace empty value to null with SQL?

Let us say, I want to find the second highest salary. For that I use the following query. However, I want this to return null when the table only contains one entry, and therefore there is no 2nd highest salary. How can I do that? Answer Use your query with aggregation: The aggregate function max() will retur…

SQL SELF JOIN return null if not exist

Recently, I got a table A like this: I try to SELF JOIN this table by I got this What I expect is when VoucherID doesn’t have any reciprocal account, that record will return null, like this Is there any elegant approach? Thanks all. Answer Why not just use aggregation? You could also do this using left …