sql

mysql select single column as single dimension array in PHP

风格不统一 提交于 2021-02-16 18:07:45
问题 I'm selecting a single column from my mysql database: $savedSQL = 'SELECT can_id FROM savedsearches WHERE user_id = "'.mysql_real_escape_string($user_id).'" AND insertTime >= "'.$lastSigTime.'"'; $savedQuery = mysql_query($savedSQL); And I'd like to return the values as a single dimension, enumerated array such that array[0] = row1, array[1] = row2, etc. When I put it into an array like this: while($savedResult = mysql_fetch_array($savedQuery)) { $savedArray[] = $savedResult; } It returns it

Table Variables in Azure Data Warehouse

谁都会走 提交于 2021-02-16 15:58:20
问题 In a SQL Server database, one can use table variables like this: declare @table as table (a int) In an Azure Data Warehouse, that throws an error. Parse error at line: 1, column: 19: Incorrect syntax near 'table' In an Azure Data Warehouse, you can use temporary tables: create table #table (a int) but not inside functions. Msg 2772, Level 16, State 1, Line 6 Cannot access temporary tables from within a function. This document from Microsoft says, ◦Must be declared in two steps (rather than

How do I get the latest record for each item in CosmosDB using SQL

微笑、不失礼 提交于 2021-02-16 15:36:29
问题 I have a schema which is similar to "id": "uuid", "deviceId": "uuid", "message": { "content": "string", "ts": 1 }, "data": { "temperature": 21 } I'd like to get the latest "data" (using message.ts as the timestamp) for each "deviceId". So far, I've managed to get the data back, in order of timestamp using the query SELECT c.deviceId, c.message.ts, c.data FROM c ORDER BY c.message.ts DESC but I can't figure out how to remove the duplicate device records. Is this possible to do within the

how to save only time not date in database through sql query

百般思念 提交于 2021-02-16 15:31:28
问题 this query is saving complete date and time. but i want to save only time not date in database. is there any query to do this? update table set current_time=now(); 回答1: Your column must be set to either DATETIME or TIMESTAMP. If you use the TIME type then your query would work as expected. If you are using any other type of column then you could use CURTIME() method or CAST(column AS TIME) as mentioned by other answers, however this would use more space on disk, and make for much slower

Remove minutes from datetime - sql

柔情痞子 提交于 2021-02-16 15:01:10
问题 DECLARE @MinutesToAdd int = 20; DECLARE @StartTimeDate datetime = '2017-06-05 14:37:56.113'; DATEADD(minute,@MinutesToAdd,@StartTimeDate); Code above adds 20 minutes to StartTimeDate. Is there a good way to remove those 20 minutes not add? Tried to find a solution, but didn't catch one. Any ideas? 回答1: You don't have any specific function to subtract any dateparts Just add negative symbol in front Select DATEADD(minute,-@MinutesToAdd,@StartTimeDate); or multiply with -1 Select DATEADD(minute,

Remove minutes from datetime - sql

房东的猫 提交于 2021-02-16 15:00:27
问题 DECLARE @MinutesToAdd int = 20; DECLARE @StartTimeDate datetime = '2017-06-05 14:37:56.113'; DATEADD(minute,@MinutesToAdd,@StartTimeDate); Code above adds 20 minutes to StartTimeDate. Is there a good way to remove those 20 minutes not add? Tried to find a solution, but didn't catch one. Any ideas? 回答1: You don't have any specific function to subtract any dateparts Just add negative symbol in front Select DATEADD(minute,-@MinutesToAdd,@StartTimeDate); or multiply with -1 Select DATEADD(minute,

Calculate difference between start_time and end_time in seconds from unix_time yyyy-MM-dd HH:mm:ss

妖精的绣舞 提交于 2021-02-16 14:52:57
问题 I'm still learning SQL and I found a couple of solutions on SQL Server or Postgreы, but it doesn't seen to work on HUE DATEDIFF , only allows me to calculate difference between days seconds, minutes are not available. Help is very welcome. I was able to split the timestamp with substring_index , but then I can't find the right approach to compare and subtract start_time to end_time in order to obtain the accurate account of seconds. I can't find time functions so I'm assuming I should

SQL INNER JOIN on Text Columns

岁酱吖の 提交于 2021-02-16 14:25:10
问题 I have two tables (equipment & software) that I want to do an INNER JOIN on. They both have a field called EQCN. It is a text field. I get the following error: The data types text and text are incompatible in the equal to operator. There has to be a way around this. 回答1: Change the data types for these columns to varchar(max) . From Microsoft: ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work,

Postgres UPDATE using rank window function

别等时光非礼了梦想. 提交于 2021-02-16 13:58:13
问题 I have a table called medias where I've just recently added a new column to called sort_order of type Int . The row values will not be unique to the entire table, but to their own respective owner_user_id fields. Regardless, I don't even care about the uniqueness of them tbh. The point of all this is to allow users to set the sort order of the photos they upload (up to 10, and they can drag and re-order, etc). When the user "deletes" a photo, I don't remove the record, I simply set a visible

MySQL application users vs database users

别等时光非礼了梦想. 提交于 2021-02-16 13:43:47
问题 Unfortunately this question may be a little broad, because I can't work out the proper terms to help me bring all this together. I'm very new to php/SQL, and I'm attempting to set up a minimal site with very simple login/register functionality. Should I be creating a new database user whenever I register a new web user? Are CRUD privileges safe to give to all users of the website? Should I actually make a DB user for registering, one which can only insert into the user table and nothing else