Table contains columns id, fid, created_date.
fid is not present in all rows.
Here is my sql query:
select count(*) fid from users where created_on between '2017-01-06 00:00:000' AND '2017-01-06 23:59:59.997' not in ('');
I want to count fid rows between dates, I tried with this query but it is not returning proper output, I am getting total count in result, I want count between the dates I entered
Try
select count(*) from users where created_on between '2017-01-06 00:00:00' AND '2017-01-06 23:59:59';
Related
I need id of each row where column start_time and end_time have same value and count of rows is equal to or greater than 3. In below table structure the id 4,7,8 have same value in start_time column, end_time column and count of row 4,7,8 is 3, so i want a query where it would only return me id 4,7,8 if count is equal to or greater than 3.
So far i came up with this query using groupby start_time and end_time, but the approach is wrong because it will only return the first id in the table when grouped by and not returning all of them.
Any Help is appreciated in advance.
Edit
Sorry, I forgot to mention order has a relationship with order_status_history table, the foreign key is order_id. The count should only be considered if start_time, end_time in order table is same AND in order_status_history table relevant order_id is_current = true AND status_keyword' can be any of these ['pending', 'accepted', 'on_the_way', 'assigned', 'reached', 'started'].
To sum up non of the 3 records (4,7,8) should show up, if status_key is not any of this ['pending', 'accepted', 'on_the_way', 'assigned', 'reached', 'started'] OR is_current = false.
order_status_history Structure:
Query:
select COUNT(*), `id`, `start_time`, `end_time` from `orders` group by `start_time`, `end_time`
Result Of Above Query:
Table Structure:
SELECT id
FROM orders
WHERE (start_time, end_time) IN (
SELECT start_time, end_time
FROM orders
GROUP BY start_time, end_time
HAVING COUNT(*) > 3)
I am trying to to perform an insert using the following:
INSERT INTO stock_withholds (s_id, mob, paddock, product, completed_date, withhold_until_date, ESI_withhold_until_date)
SELECT stk_id AS s_id,
mob,
paddock,
product,
completed_date,
withhold_until_date,
ESI_withhold_until_date
FROM stock_current
WHERE (withhold_until_date >=CURDATE()
OR (ESI_withhold_until_date >= CURDATE()
AND stock_current.stk_id NOT IN
(SELECT s_id
FROM stock_withholds)
If I rerun the query it duplicates the records.
Desired result is if either the withhold_until_date or ESI_withhold_until_date are greater then current date the records would inserted.
Thanks
I have a table with the following rows. id, address, timestamp. Timestamp is a unix timestamp. How can I get the day that has the most rows, and the number of rows in that day using 1 query. I am using MySQL 5.6.34.
Group the rows by date, use COUNT(*) to get the count of rows in each group, and then use ORDER BY and LIMIT to get the highest count.
SELECT DATE(timestampColumn) AS date, COUNT(*) AS count
FROM yourTable
GROUP BY date
ORDER BY count DESC
LIMIT 1
Hi i am trying to get the count of records per day which i can do, but i also want the date to be show, for example,
Result
Date | Count
26/01/2015 20
25/01/2015 | 413
Here is an example of my data.
I would think this would work. Replace 'yourTable' with your table name
SELECT Date, COUNT(*) FROM yourTable GROUP BY Date;
Get the total count and group them by date.
SELECT `date`, COUNT(*) as Total
FROM `table`
GROUP BY `date`
ORDER BY `date`;
I want to select data from a table, group by this data with the date value maximum.
In my table i have 4 columns - id, message_id, client_id and date. column id is unique and auto incremented, while message_id and client_id have duplicate values. date is almost unique.
I want to select all records, group by message_id and client_id, that has date maximum.
my query is -
SELECT *,MAX(`date`) AS `maxdate` FROM `table_name` group by `message_id`,`client_id` order by `date` desc
but this does not give the date with maximum value.
I am getting the grouped record with first date.
Please help, and tell me the correct query, i am quite new to mysql.
Try this query out - this is how I would do it in Oracle:
select n1.id, n1.message_id, n1.client_id, n1.date
from shailjas_note n1
where n1.date = (select max(n2.date)
from shailjas_note n2
where n1.message_id = n2.message_id
and n1.client_id = n2.client_id)