Jump to content

Search the Community

Showing results for tags 'union all'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 2 results

  1. I'm stuck like a wheel barrow in the mud. Wondering if someone might be able to help me write this query. I have a table where status change dates are held. I'm trying to build a query that sums each of the columns by date. In the end.... I should have a column of dates in the first column. several columns as listed below. (created, offers, contracts, closed, sold) Then the total number of records with dates that match the row date. (It think that makes sense) So I can tell ... how many records were created on each day. how many offers were made on each day etc etc. Here is the query I have so far which doesn't quite work. Display is attached. select * from ( select `date`, sum(created) created, sum(offers) offers, sum(contracts) contracts, sum(closed) closed, sum(sold) sold from ( select DATE(from_unixtime(created)) `date`, count(*) created, 0 as offers, 0 as contracts, 0 as closed, 0 as sold from properties union all select DATE(from_unixtime(offer_date)) `date`, 0 as created, count(*) as offers, 0 as contracts, 0 as closed, 0 as sold from properties union all select DATE(from_unixtime(contract_date)) `date`, 0 as created, 0 as offers, count(*) as contracts, 0 as closed, 0 as sold from properties union all select DATE(from_unixtime(purchase_date)) `date`, 0 as created, 0 as offers, 0 as contracts, count(*) as closed, 0 as sold from properties union all select DATE(from_unixtime(sale_date)) `date`, 0 as created, 0 as offers, 0 as contracts, 0 as closed, count(*) as sold from properties )a group by a.`date` )b
  2. Someone gave me a script that works - but it doesn't work for me. I've been trying to debug it, but I'm striking out. First, let's start with a simple query: $sql= "SELECT COUNT(URL) AS num FROM people WHERE URL = :MyURL"; It works, where a URL is MySite/Carl_Sagan and $MyURL = 'Carl_Sagan' I have several similar queries for various websites and sections. I want to try to merge everything into a new website that will function kind of like a mini encyclopedia. So I use UNION ALL to link several queries together, like this... $sql = "SELECT SUM(num) FROM ( SELECT COUNT(URL) AS num FROM pox_topics WHERE URL = :MyURL UNION ALL SELECT COUNT(URL) AS num FROM people WHERE URL = :MyURL UNION ALL SELECT COUNT(Taxon) AS num FROM gz_life WHERE Taxon = :MyURL ) AS X"; $stmt = $pdo->prepare($sql); $stmt->bindParam(':MyUrl',$MyURL,PDO::PARAM_STR); $stmt->execute(); $Total = $stmt->fetch(); switch($Total['num']) { case 1: // ETC.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.