between

MySQL UPDATE with random number between 1-3

橙三吉。 提交于 2019-12-17 17:47:18
问题 Got a big table and I want to add a column that has a randomly chosen number for each record. 1, 2, or 3. Having a hard time. Any ideas? 回答1: Try this: UPDATE tableName SET columnName = FLOOR( 1 + RAND( ) *3 ); From the MySQL documentation for RAND : Returns a random floating-point value v in the range 0 <= v < 1.0. So in the above query, the largest value which could be generated by 1 + RAND()*3 would be 3.999999 , which when floored would give 3. The smallest value would occur when RAND()

Check if current date is between two dates Oracle SQL

*爱你&永不变心* 提交于 2019-12-17 09:19:41
问题 I would like to select 1 if current date falls between 2 dates through Oracle SQL. I wrote an SQL after reading through other questions. https://stackoverflow.com/questions/2369222/oracle-date-between-query https://stackoverflow.com/questions/2399753/select-from-table-by-knowing-only-date-without-time-oracle But it returned only null. sysdate is the current date that is 01/05/2014 in date format DD/MM/YYYY . The SQL I wrote is: select 1 from dual WHERE to_date(sysdate,'DD/MM/YYYY') BETWEEN TO

Select all months within given date span, including the ones with 0 values

岁酱吖の 提交于 2019-12-17 06:16:08
问题 I'm trying to write a MySQL query to get an average value per month, for all months between to given dates. My idea is this: Query, something like SELECT AVG(value1) as avg_value_1, AVG(value2) as avg_value_2, MONTH(save_date) as month, YEAR(save_date) as year FROM myTable WHERE save_date BETWEEN '2009-01-01' AND '2009-07-01' GROUP BY YEAR(save_date), MONTH(save_date) avg_value_1 | avg_value_2 | month | year 5 | 4 | 1 | 2009 2 | 1 | 2 | 2009 7 | 5 | 3 | 2009 0 | 0 | 4 | 2009 <--- 6 | 5 | 5 |

SQL : BETWEEN vs <= and >=

折月煮酒 提交于 2019-12-17 03:28:09
问题 In SQL Server 2000 and 2005: what is the difference between these two WHERE clauses? which one I should use on which scenarios? Query 1: SELECT EventId, EventName FROM EventMaster WHERE EventDate BETWEEN '10/15/2009' AND '10/18/2009' Query 2: SELECT EventId, EventName FROM EventMaster WHERE EventDate >='10/15/2009' AND EventDate <='10/18/2009' (Edit: the second Eventdate was originally missing, so the query was syntactically wrong) 回答1: They are identical: BETWEEN is a shorthand for the

Retrieve data within a date range in Oracle

谁都会走 提交于 2019-12-13 07:57:09
问题 I have a table tbldeptdivision as follows: ID DEPTID DIVISIONID FROMDATE TODATE REMARKS --- ------- ----------- ----------- ----------- -------- 21 21 5 31-AUG-99 01-JAN-80 NULL I have the query select * from tbldeptdivision where deptid = 21 and trunc(sysdate) between to_date(fromdate,'dd-Mon-yyyy') and to_date(todate,'dd-mon-yyyy'); It returns me no value. Can anybody say why? '31-AUG-99' is actually '31-AUG-1999' and '01-JAN-80' is actually '01-JAN-2080' . What will be the exact query? 回答1

Mysql between two datetime columns

爷,独闯天下 提交于 2019-12-13 07:25:21
问题 I have the following code and it doesn't seem to be generating the expected results: $date_from = '2012-04-27 18:19:33'; $date_to = '2012-05-29 00:59:57'; $database->connect(); $ancestors = mysql_query(' SELECT * FROM ' . $database->db_prefix . 'comments e WHERE e.created BETWEEN "' . $date_from . '" AND "' . $date_to . '" AND e.ancestors = "' . $comment["id"] . '" AND e.user_id != "' . $user->user_object["id"] . '" AND NOT EXISTS ( SELECT null FROM ' . $database->db_prefix . 'notifications d

calculate if date value occurs between two different times python pandas

自作多情 提交于 2019-12-13 03:44:35
问题 I am trying to create a new column to determine if a row value is "between business hours". To do this I am trying to use the between time function. I dont need to use it if there is an easier way. I have a dataframe with columns for 'Date' , 'StartHour' , 'End Hour' . Question: I would like to give a 'True' or 'False' if the time in the ' Date ' column is between the ' StartHour ' and ' EndHour ' time. import pandas as pd import numpy as np #create dataframe with dates d = {'Date': ['2016-11

MySQL average number of hours between created datetimes for a specific time interval

心已入冬 提交于 2019-12-13 03:43:50
问题 I have a table with a field called "created" which is a datetime field. Assume NOW() is midnight on 2013-07-21, so NOW() = 2013-07-21 23:59:59 Now let's say I query for all records WHERE created BETWEEN DATE_SUB(NOW(), INTERVAL 4 DAYS) AND NOW() Let's say that returns results like this: 2013-07-18 08:00:00 2013-07-19 08:00:00 2013-07-20 08:00:00 2013-07-21 08:00:00 I want to add the start and end datetime for the interval I used (4 days) to that result set, so now I have: 2013-07-18 00:00:00

SQL count open tasks each day

三世轮回 提交于 2019-12-13 02:47:45
问题 I've tried to use the search function and found a similar question. However, I can't get it to work properly. I have a simple table that shows incoming and ended e-mails (tasks). There's an ingoing and ended-date. For analysis I want to show (historical) the number of open/unanswered e-mails for a given day back in time. The output should answer the question: "What was the number of open tasks yyyy-mm-dd?". The number of open tasks a given day (yyyy-mm-dd) should be Count WHERE Date_IN < yyyy

SQL, Selecting between date/times

安稳与你 提交于 2019-12-13 00:23:24
问题 This is for (MS SQL Server 2008) It allows the user to schedule other users for a start and end date/time without overlaps. I'm addressing the business rule of not being able to overlap individuals during a schedule. E.G, If user 1 is scheduled from 1/1/2012 to 1/4/2012, user 2 should not be able to submit a request for 1/2/2012 to 1/4/2012. This part is already taken care of, and here is my SQL. SELECT * FROM fooTable WHERE Prim = 1 AND Group = 10 AND (('2012-06-01 08:01' between startdate