2015-04-24 68 views
0

我有一個MySQL日誌表,它有一個json字符串列。 json字符串包含年,月,日,小時,分鐘等,並自動插入爲日誌。MySQL選擇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

你可以試試這個:

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"%')