I can not insert timestamp value '2015-01-07 00:00:00' into my database.
This issue works for any hour between 2015-01-07 00:00:00 and 2015-01-07 01:00:00
This works ONLY for the 7th of January of 2015.
SHOW VARIABLES LIKE "%version%";
protocol_version 10
version 5.1.50-community
version_comment MySQL Community Server (GPL)
version_compile_machine ia32
version_compile_os Win32
==
CREATE TABLE `eventtest3` (
`event_dt` TIMESTAMP
) ENGINE=INNODB DEFAULT CHARSET=utf8
1 queries executed, 1 success, 0 errors, 0 warnings
0 row(s) affected
==
And my insert query is:
1 queries executed, 0 success, 1 errors, 0 warnings
Query: INSERT INTO eventtest3 (event_dt) VALUES('2015-01-07 00:00:00')
Error Code: 1292
Incorrect datetime value: '2015-01-07 00:00:00' for column 'event_dt' at row 1
==
Working queries:
Query: INSERT INTO eventtest3 (event_dt) VALUES('2017-01-07 00:00:00')
1 queries executed, 1 success, 0 errors, 0 warnings
1 row(s) affected
Query: INSERT INTO eventtest3 (event_dt) VALUES('2014-01-07 00:00:00')
1 queries executed, 1 success, 0 errors, 0 warnings
1 row(s) affected
Query: INSERT INTO eventtest3 (event_dt) VALUES('2016-01-07 00:00:00')
1 queries executed, 1 success, 0 errors, 0 warnings
1 row(s) affected
1 queries executed, 1 success, 0 errors, 0 warnings
Query: INSERT INTO eventtest3 (event_dt) VALUES('2015-01-31 05:07:09')
1 row(s) affected
There is no time shifting here or there on this date so I dont think this issue is because of timezone settings.
The solution is to check if mysql.time_zone* tables are empty, download timezones information from http://dev.mysql.com/downloads/timezones.html and just replace tables with stopped mysql service.
I don't really know HOW this can help with 7th of January of 2015 but it really does.
Related
I have an SQLite table as such:
A
B
0
0
1
1
and the following trigger specs that fire on update or insert for each column:
A = 0
B = 1
In the application, I need to display the rows that break the specs, with culprit fields highlighted, as such:
A
B
0
0
1
1
I honestly don't know how to approach this. Would this require that I somehow return a 'bitmap' of the table along with the selected data? Is there a better way to 'tag' fields?
Thanks!
In a query all you can have is 2 extra flag columns (one for each of the columns A and B) with 0 or 1:
SELECT *,
A = 0 flag_A,
B = 1 flag_B
FROM tablename;
In your application you can check the values of the flag columns and highlight a column if its flag is equal to 0.
See the demo.
I have a table TABLE in SQLite database with columns DATE, GROUP. I want to select the first 10 entries in each group. After researching similar topics here on stackoverflow, I came up with the following query, but it runs very slowly. Any ideas how to make it faster?
select * from TABLE as A
where (select count(*) from TABLE as B
where B.DATE < A.DATE and A.GROUP == B.GROUP) < 10
This is the result of EXPLAIN QUERY PLAN (TABLE = clients_bets):
Here are a few suggestions :
Use a covering index (an index containing all the data needed in the subquery, in this case the group and date)
create index some_index on some_table(some_group, some_date)
Additionally, rewrite the subquery to make is less dependent on outer query :
select * from some_table as A
where rowid in (
select B.rowid
from some_table as B
where A.some_group == B.some_group
order by B.some_date limit 10 )
The query plan change from :
0 0 0 SCAN TABLE some_table AS A
0 0 0 EXECUTE CORRELATED LIST SUBQUERY 1
1 0 0 SEARCH TABLE some_table AS B USING COVERING INDEX idx_1 (some_group=?)
to
0 0 0 SCAN TABLE some_table AS A
0 0 0 EXECUTE CORRELATED SCALAR SUBQUERY 1
1 0 0 SEARCH TABLE some_table AS B USING COVERING INDEX idx_1 (some_group=? AND some_date<?)
While it is very similar, the query seems quite faster. I'm not sure why.
The current update statement is
UPDATE Table1 t1
SET column1 = 1
WHERE not EXISTS
( SELECT 1 FROM Table2 t2
WHERE t2.column2= t1.column2
AND t2.column1 = 0
)
AND t1.column2 > 0
AND t1.column1 = 0
The above update statement is fine if I have the value of 0 in column1 in the table Table t2. But I have a special scenario that my table Table t2 is having values as 0 and 1 for column1. In this case there should not be no update. In a single statement i have to handle both the situation.
Scenario 1: Update only if Column1 in the Table t2 having the value of 0
Scenario 2: No update if I Column1 in the Table t2 having the value of both 0 and 1
Can you please help me in this.
Looking to find all part numbers (d046d) with at least one record having vaule greater than zero.
d046d e024a
ABC123 0
ABC123 0
ABC123 0
123ABC 0
123ABC 1
123ABC 0
1A2B3C 0
1A2B3C 0
All I want returned is 123ABC
SELECT d008g, d046d, e024a
FROM 20121
WHERE (20121.[d046d])=(select sc.d046d from 20121 as sc where e024a >0)
This will error becuase it will find multiple d046d in the subquery.
If what you want is just those parts with a quantity greater than zero, then your where clause should probably just say
WHERE e024a > 0
Now you say you want part numbers where at least one record is > 0, so then I can conclude that you only want to see each qualifying part number once - this is best achieved by using
DISTINCT:
SELECT DISTINCT d008g, d046d, e024a
FROM 20121
WHERE e024a > 0
You can use an In Operator. In Operator Reference
SELECT d008g, d046d, e024a
FROM 20121
WHERE (20121.[d046d]) In (select sc.d046d from 20121 as sc where e024a >0)
This is quite clumsy.
Initial info: There's a clumsy select query eventually returning 0 or 1 depending on several conditions. Usually it get's to select only one row (other data is cut of by where, etc.). The problem occurs when there's more rows to parse. So the data actually looks like follows:
Status
0
1
instead of
Status
1
Problem: Only one rowed data is needed in return, i.e. if there's a 1 present in any row, it should 1 returned, otherwise 0.
Condition: It should be done only in a query (no variables, ifs etc.).
Thanks in advance.
If you are sure that 1 and 0 are the only valuesbeing returned, Can't you use a max over this query to see any 1s..?
select max(id) result
from (
select 1 id from dual
union all
select 0 id from dual
)
RESULT
----------
1
1 select max(id)
2 from (
3 select 0 id from dual
4 union all
5 select 0 id from dual
6 union all
7 select 0 id from dual
8* )
SQL> /
MAX(ID)
----------
0