SELECT MAX( PRC_MIN_LENGTH ) PRC_MIN_LENGTH, MIN( PRC_MAX_LENGTH ) PRC_MAX_LENGTH, MAX( PRC_MIN_WIDTH ) PRC_MIN_WIDTH, MIN( PRC_MAX_WIDTH ) PRC_MAX_WIDTH
FROM (
SELECT PRDT_PRICE_CODE, MIN( PRC_MIN_LENGTH ) PRC_MIN_LENGTH, MAX( PRC_MAX_LENGTH ) PRC_MAX_LENGTH, MIN( PRC_MIN_WIDTH ) PRC_MIN_WIDTH, MAX( PRC_MAX_WIDTH ) PRC_MAX_WIDTH
FROM PRODUCT_PRICE_INFO
WHERE PRDT_PRICE_CODE
IN (
SELECT PRDT_PRICE_CODE
FROM PRODUCT
WHERE PRODUCT_ID =1
UNION SELECT PRDT_PRICE_CODE
FROM PRODUCT_OPTION
WHERE PROD_OPT_ID
IN (
'1', '101', '201', '303', '401'
)
)
AND CURDATE( )
BETWEEN DATE_SUB( CURDATE( ) , INTERVAL 1
DAY )
AND DATE_ADD( CURDATE( ) , INTERVAL 1
DAY )
GROUP BY PRDT_PRICE_CODE
)PRC_RANGE
This query is running in MySQL database but not in SQLite.
Where is the mistake and how can I fix this?
SQLite uses different date functions.
You would have to write the date comparison like this:
...
AND date('now') BETWEEN date('now', '-1 days')
AND date('now', '+1 days')
...
(This is a faithful translation, and will make the query run; but it's doubtful that this query does what you want in either MySQL or SQLite.)
Related
Alright I have tried alot and this looks just about right for me , but its def not:
SELECT COUNT( DISTINCT 'uid' ) AS `Records` , DATE( FROM_UNIXTIME( `epoch_timestamp` ) ) AS `Date`
FROM `log`
GROUP BY DATE( FROM_UNIXTIME( `epoch_timestamp` ) )
LIMIT 0 , 30
For w.e reason it returns a 1 next to each date. If I take out the distinct it appears to give a total records for that day count.
Seems like your sql is incorrect, try replacing the single quotation marks around 'uid' with `.
SELECT COUNT( DISTINCT `uid` ) AS `Records` , DATE( FROM_UNIXTIME( `epoch_timestamp` ) ) AS `Date`
FROM `log`
GROUP BY DATE( FROM_UNIXTIME( `epoch_timestamp` ) )
LIMIT 0 , 30
with this query i aim to retrieve data from another table in a subquery where arguments compare unixtime stamp. But the result in my third columne ('valid') remains empty?
SELECT COUNT( valid.call_id )FROM calls AS valid WHERE SECOND((
SELECT conf.cca_setvalidtime FROM user_conf AS conf
WHERE MONTH(FROM_UNIXTIME(conf.activ_date)) = MONTH(FROM_UNIXTIME(valid.last_call ))
)) < SECOND( valid.call_duration )
) AS 'valid'
FROM calls
GROUP BY EXTRACT(
YEAR_MONTH FROM last_call )
Here is the Solution for anyone who can need something alike ;-)
SELECT DATE_FORMAT( last_call, '%M' ) AS 'month', COUNT( call_id ) AS 'total', (
SELECT COUNT( valid.call_id )
FROM calls AS valid
WHERE TIME((
SELECT conf.cca_setvalidtime FROM user_conf AS conf
WHERE EXTRACT(YEAR_MONTH FROM conf.activ_date ) = EXTRACT(YEAR_MONTH FROM valid.last_call ) AND conf.for_role=1
)) < TIME( valid.call_duration )
AND EXTRACT(
YEAR_MONTH FROM valid.last_call ) = EXTRACT(
YEAR_MONTH FROM calls.last_call )
) AS 'valid'
FROM calls
GROUP BY EXTRACT(
YEAR_MONTH FROM last_call )
Highcharts dont display statistics with MySQL Query
It Works:
$this->db->query("SELECT COUNT( gt ) as sayi , FROM_UNIXTIME( tarih, '$periyot' ) AS gun
FROM sayigoruntu
WHERE tarih >= DATE_SUB( CURDATE( ) , INTERVAL 1 MONTH ) and gt='$gt'".$sqlek."
GROUP BY gun
ORDER BY gun");
Output:
[[3582],[2062],[140],[4425],[294]]
$this->db->last_query() Result:
SELECT COUNT( gt ) as sayi , FROM_UNIXTIME( tarih, '%Y.%m.%d' ) AS gun FROM sayigoruntu WHERE tarih >= DATE_SUB( CURDATE( ) , INTERVAL 1 MONTH ) and gt='0' GROUP BY gun ORDER BY gun
This works without problems but this doesn't work (PHP):
if($siteid !=''){
$sqlek="and sid='".$siteid."'";
}
SQL Query:
SELECT COUNT( gt ) as sayi , FROM_UNIXTIME( tarih, '$periyot' ) AS gun
FROM sayigoruntu
WHERE tarih >= DATE_SUB( CURDATE( ) , INTERVAL 1 MONTH ) and gt='$gt'".$sqlek."
GROUP BY gun
ORDER BY gun
Output:
[[3582],[2062],[140],[4425],[294]]
$this->db->last_query() result:
SELECT COUNT( gt ) as sayi , FROM_UNIXTIME( tarih, '%Y.%m.%d' ) AS gun FROM sayigoruntu WHERE tarih >= DATE_SUB( CURDATE( ) , INTERVAL 1 MONTH ) and gt='0' GROUP BY gun ORDER BY gun
Same Output, Same Queries but not working. Error reason maybe ".$sqlek." on MySQL Query.
Is MySQL Query Right Or is this a Highcharts Error?
Your form is incorrect, it should be array of numbers or array of arrays but including x/y. Not an array of arrays with single value. How you refer your data to javascript?
I'm sending 4 values for the sql query through a jaggery script. Here is the sql query:
SELECT full_name , sum( amount ) AS total
FROM hourlyusage , user
WHERE DAY = DATE( DATE_SUB( NOW( ) , INTERVAL ? HOUR ) )
AND HOUR BETWEEN HOUR( DATE_SUB( NOW( ) , INTERVAL ? HOUR ) )
AND HOUR( DATE_SUB( NOW( ) , INTERVAL 1 HOUR ) )
AND hourlyusage.userIp = user.ip_address
AND (user.full_name LIKE '%?%' OR user.user_name LIKE '%?%') GROUP BY full_name
But it gives an exception like this.
Nested Exception:-
java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2).
What would be the reason for that?
SELECT full_name , sum( amount ) AS total
FROM hourlyusage , user
WHERE DAY = DATE( DATE_SUB( NOW( ) , INTERVAL ? HOUR ) )
AND HOUR BETWEEN HOUR( DATE_SUB( NOW( ) , INTERVAL ? HOUR ) )
AND HOUR( DATE_SUB( NOW( ) , INTERVAL 1 HOUR ) )
AND hourlyusage.userIp = user.ip_address
AND (user.full_name LIKE ? OR user.user_name LIKE ?) GROUP BY full_name
You cannot use wildcard in the sql query so try to remove the wildcard from the sql and add it to the value.As you have done '%?%' in sql says that you need global match.Do that in your value not in sql query.
SELECT date( `captureTime` ) dateDay, DATE_FORMAT( `captureTime` , '%H' ) dateHour, DATE_FORMAT( `captureTime` , '%i' ) dateQuarter, max( channel1_Data ) , max( channel2_Data ) , max( channel3_Data ) , min( channel1_Data ) , min( channel2_Data ) , min( channel3_Data )
FROM `sensordata`
WHERE `Sensor_sensorSerialNo` =1
AND `captureTime` >= '2011-10-16 22:15:11'
AND `captureTime` <= '2011-10-17 23:59:59'
I want to get all data from 2011-10-16 22:15:11 to 2011-10-17 23:59:59 after running the select query. And the 'captureTime' column also need be divided into three columns(i.e. 'dateDay', 'dateHour' and 'dateQuater'). However, only get one row result after running the above query. I can't see anything wrong there.
Can anyone point out the errors? Thanks in advance!
min, max functions are aggregate functions and are usually used with Group By clause. However If you are not using Group By clause then Min or Max value will be returned after performing calculation on complete table data. So, only one row should be returned, that would be minimum or maximum. If you want other columns to be selected, then those columns must be present in Group By clause.
MySql allowed this query to execute, but other dbms such as SQLServer wont even allow this query to be executed.
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html
Try using like:
SELECT date( `captureTime` ) as "dateDay", DATE_FORMAT( `captureTime` , '%H' ) as "dateHour", DATE_FORMAT( `captureTime` , '%i' ) as "dateQuarter", max( channel1_Data ) , max( channel2_Data ) , max( channel3_Data ) , min( channel1_Data ) , min( channel2_Data ) , min( channel3_Data ) FROM `sensordata` WHERE `Sensor_sensorSerialNo` =1 AND `captureTime` >= '2011-10-16 22:15:11' AND `captureTime` <= '2011-10-17 23:59:59'