count

How to use an sql subquery that uses count.

I have a system where reservations are stored as records in one table(workshop_reservation) and sessions (the things being reserved) are stored in another table(session). Each reservation belongs to a session, and each session belongs to a workshop. I want to make a mysql query that finds the number of reservations for each session that...

help with count with left join

hello I have 2 tables 1st table called services has id_service, name, date. 2nd table called services_images has id_img, img_name, id_service. What I wanna do is get list of services with a row called num_images that counts how many images there are per service. I tried this SELECT COUNT(services_images.id_img) as num_images, serv...

SQL LEFT JOIN with COUNT(*) problem

I have the following query: SELECT products_categories.categoryID, name, COUNT(*) AS itemCount FROM products_categories LEFT JOIN products_to_categories ON products_to_categories.categoryID = products_categories.categoryID GROUP BY products_categories.categoryID But still there's a problem: categories with no products in them return i...

SELECT DISTINCT and count

Hello, the table looks like this: tag | entryID ----+--------- foo | 1 foo | 2 bar | 3 And now i want to get all tags with its usage: foo | 2 bar | 1 How can I do this? Thank you ...

mysql distinct value for count

I am all over the place here. The MySql query below works for me except for two issues. 1) I want to make sure that only one result per category is displayed (I have 5 categories), I tried using DISTINCT but have clearly misunderstood that one. 2) I want to be able to return the howmany value outside the sql query: "SELECT DISTINCT ca...

Mysql num rows on multiple tables using UNION

Hi all, I'm trying to find number of rows for two tables: Example 1 returns 81 (which is wrong). SELECT p_id FROM j_posts INNER JOIN j_blogs ON p_blog_id = b_id && b_approved = 1 WHERE p_is_draft = 0 UNION SELECT ep_id FROM j_external_posts INNER JOIN j_blogs ON ep_blog_id = b_id && b_approved = 1 I have then tried to split up th...

Rails output number of records with X in field?

Hi Everyone, I have a number of records in a model called Kases, each kase record has a status which can be Active, On Hold, Invoice Sent or Archived. I am trying to work out how to add a number on the dashboard for the total number of kase records, the total number of kase records marked as on hold, the total number of kase records m...

Determine if a file has more than X lines?

Hi there, as I was not able to find a function which retrieves the amount of lines a file has, do I need to use $handle = fopen("file.txt"); For($Line=1; $Line<=10; $Line=$Line+1){ fgets($handle); } If feof($handle){ echo "File has 10 lines or more."; }Else{ echo "File has less than 10 lines."; } fclose($handle) or something si...

Count the number of checked check-boxes and display them on a fixed div using jQuery

I'm trying to write a jQuery script (I have never written one before and I need help). The details are as following; I have a form with check-boxes. Each check-box has a different id and name which I will need for my own programming reasons. What I simply want is to count the number of check-boxes and simply display it on the right side ...

SQL Count across 3 tables

I have a query that works fine when there is data but not when I have nothing in the charities table. Any help would be hugely appreciated. SELECT C.CategoryId , C.CategoryName , ISNULL(COUNT(CC.CharityId), 0) as CharityCount , C.IsDeleted FROM Charity.Categories C LEFT JOIN Charity.CharityCategories CC on C.CategoryId =...

MySQL - Why is COUNT with "greater than" quick but "less than" takes forever?!

SELECT count(*) c FROM full_view WHERE verified > ( DATE (NOW()) - INTERVAL 30 DAY) If I run that query it takes a split second but if I switch the comparison operator around it takes eons. Now the first way the count = 0 and the second way the count = 120000, but if I just count the whole table that also takes microseconds. But there...

Oracle SQL query count group by timestamp substring

Given a table that has a column of string "timestamps" (yyyyMMddHHmmssSSS format), I want to substring the first 8 characters, and get a count of how many rows have that substring, grouping the results. Sample data... TIMESTAMP 20100802123456123 20100803123456123 20100803123456123 20100803123456123 20100804123456123 20100805123456123 2...

XSLT 1.0 word count with HTML

I am looking to call a template that will trim down a field to 30 words. However, this field contains HTML and the HTML should not count as a word. ...

What is $variable[count($variable)-1] Doing?

It's a simple question, but no matter where I look, I can't seem to figure out how it works. I believe it's taking the first character off the beginning of $variable, but how does count($variable)-1 do this? $variable[count($variable)-1] Full code: $fileType = explode('.',$_FILES['Filedata']['name']); $fileName = str_ireplace('.jpg'...

I need a SQL statement that returns the number rows in a table with a specific value.

I'm sure this will equate down to the use of the COUNT statement but I'm not very good at SQL. Here are my SQL Tables. Teams Table: TeamId TeamName RosterSpots ----------------------------------------------- 1 Miami Heat 12 2 New York Knicks 10 Players Table: PlayerId PlayerName ...

count and remove duplicate access vba

Here is some code I have to remove duplicate occurances of catid & recid in tblcat1_rec table, leaving only 1 entry: mysql = "DELETE FROM tblcat1_rec " mysql = mysql & " WHERE ID <> (SELECT Min(ID) AS MinOfID FROM tblcat1_rec AS Dupe " mysql = mysql & " WHERE (Dupe.catid = tblcat1_rec.catid) " mysql = mysql & " AND (Dupe.recid = tblcat1...

mysql: how to collect the array data?

hi all. I have a mysql code that needs to be improved because of my limited knowledge. i am new in php-mysql.I have data arrays at my DB and I want to show data such as: Date Model Qty Name 2010-08-23 boo 2 Steve 2010-08-24 boo 1 Steve 2010-08-25 boo ...

Counting some data array not work

dear all.can you tell me how to collecting this data in mysql: item colour nut brown nut black i want the result like: item colour_qty nut 2 and i have try like this, but didn't work: SELECT item, COUNT(colour) AS colour_qty FROM mytable How do i do that?thanks. ...

SQL search, search for a|b|c|d in a table and return results ordered by number of elements in the record

the question: there are two tables - DAYS(name), ACTIONS(day_name,name) records for DAYS are: Sunday, Monday, Wednesday records for ACTIONS are: {eat,sunday}, {sleep,sunday}, {write,sunday}, {drink,sunday} {eat,wednesday}, {sleep,wednesday}, {write,wednesday}, {eat,monday}, {sleep,monday}, i want to search in ACTIONS for the day...

FLEX Video player - play count

I have a video player in flex which constantly plays a movie. Is there a way to see how many times it has played? So each time the movie is played, text filled populates with +1. Thanks, Yan ...