我有一个MySQL日志表,其中包含一个带有json字符串的列。 json字符串包含年,月,日,小时,分钟等,并自动作为日志插入。
样本表格式为
+-------+-------------------------------------------------------------------------------+
|logId | log |
+-------+-------------------------------------------------------------------------------+
| 1 | { "Year": "2015", "Month": "04", Date": "24", "Hour": "01", "Minute": "00" } |
| 2 | { "Year": "2015", "Month": "04", Date": "24", "Hour": "01", "Minute": "30" } |
| 3 | { "Year": "2015", "Month": "04", Date": "24", "Hour": "02", "Minute": "00" } |
| 4 | { "Year": "2015", "Month": "04", Date": "24", "Hour": "02", "Minute": "30" } |
| 5 | { "Year": "2015", "Month": "04", Date": "24", "Hour": "03", "Minute": "00" } |
| 6 | { "Year": "2015", "Month": "04", Date": "24", "Hour": "03", "Minute": "30" } |
| 7 | { "Year": "2015", "Month": "04", Date": "24", "Hour": "04", "Minute": "00" } |
| 8 | { "Year": "2015", "Month": "04", Date": "24", "Hour": "04", "Minute": "30" } |
| . | . |
| . | . |
| . | . |
| . | . |
| . | { "Year": "2015", "Month": "04", Date": "24", "Hour": "23", "Minute": "00" } |
| . | { "Year": "2015", "Month": "04", Date": "24", "Hour": "23", "Minute": "30" } |
| . | { "Year": "2015", "Month": "04", Date": "25", "Hour": "00", "Minute": "00" } |
| . | { "Year": "2015", "Month": "04", Date": "25", "Hour": "00", "Minute": "30" } |
+-------+-------------------------------------------------------------------------------+
现在我如何选择每天和特定日期的02 Hrs and 30 mins
和23 Hrs and 00 mins
之间的行?
答案 0 :(得分:0)
你可以试试这个:
select * from tablename where log
not exists(select 1 from tablename where
log like '%"Hour": "01", "Minute": "00"%'
or log like '%"Hour": "01", "Minute": "30"%'
or log like '%"Hour": "02", "Minute": "00"%'
or log like '%"Hour": "23", "Minute": "30"%'
or log like '%"Hour": "00", "Minute": "00"%'
or log like '%"Hour": "00", "Minute": "30"%' )